You need to do this through the family court in your county. You may wish to consult a local family lawyer, or you can just go to the County Courthouse and see if you can work through the bureaucracy.
What you're looking for is called a Protective Order in NYS, and you obtain one through a Family Court proceeding. It's not a complicated situation, provided you have legal grounds to sustain it, such as stalking, threats, physical harassment and other types of conduct.
Go to Family Court, and the clerk will tell you how to commence the proceeding. Your ex will have to be formally served with papers (by anyone over 18, except by you.)
DISCLAIMER -- THIS IS NOT LEGAL ADVICE. It is provided for general informational purpose only, does not pertain to a particular case, and does not create an attorney-client relationship.