geoclient icon indicating copy to clipboard operation
geoclient copied to clipboard

clarify how to access API

Open afeld opened this issue 3 years ago • 2 comments

I read through https://api.cityofnewyork.us/geoclient/v1/doc, and it wasn't clear to me:

  • What the base URL for the API endpoints is
  • How to get an application ID and key

It was only through a close read of https://developer.cityofnewyork.us/api/geoclient-api that I saw

Access to the service requires registering for a free account on this website and requesting an access key.

Would be great to:

  • Link from https://api.cityofnewyork.us/geoclient/v1/doc to https://developer.cityofnewyork.us/api/geoclient-api
  • Elaborate on the steps for how to go from zero to making a live request

Thanks!

afeld avatar Apr 27 '21 05:04 afeld

I agree with you that there may be documentation but Google seems to not be able to find it easily.

But here's an example:

curl -v -X GET "https://api.nyc.gov/geo/geoclient/v1/search.json?input=26+broadway" -H "Ocp-Apim-Subscription-Key: XXX"

Replace XXX with your key

ralphmapper avatar Sep 29 '21 21:09 ralphmapper

@ralphmapper thanks for the example! could you provide or point to similar in python?

EDIT: Here's the same example using python:

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Ocp-Apim-Subscription-Key': XXX
}

params = urllib.parse.urlencode({'input': '26+broadway'})

try:
    conn = http.client.HTTPSConnection('api.nyc.gov')
    conn.request("GET", "/geo/geoclient/v1/search.json*?%s" % params, "{body}",
                 headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

julietsitron avatar Oct 06 '21 19:10 julietsitron