Skip to content

Instantly share code, notes, and snippets.

@jbeezley
Last active May 13, 2019 01:21
Show Gist options
  • Save jbeezley/9979877 to your computer and use it in GitHub Desktop.
Save jbeezley/9979877 to your computer and use it in GitHub Desktop.
An example python script for making an API call to the GRITS database
#!/usr/bin/env python
import requests
import json
# main api url
url = 'https://grits.ecohealth.io/gritsdb/api/v1'
# put your username/password here
auth = ('myUsername', 'myPassword')
# request an authorization token from the server
response = requests.get(url + '/user/authentication',
auth=auth, verify=False).json()
# get the token from the response
token = response['authToken']['token']
# to make an api call using this token,
# add a token parameter to the request
params = {
'token': token,
'start': '2014-01-15',
'end': '2014-02-01',
'geoJSON': 1,
'limit': 10
}
response = requests.get(url + '/resource/grits',
params=params, verify=False).json()
# response contains the geoJSON object,
# pretty print it to the console
print json.dumps(response, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment