-
-
Save speg/29906676dfcad63732f3 to your computer and use it in GitHub Desktop.
NationBuilder Person API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This python script requires the requests HTTP library | |
# See http://docs.python-requests.org for more information. | |
import os | |
try: | |
import requests | |
except ImportError: | |
raise SystemExit("Missing requests library - http://docs.python-requests.org") | |
API_KEY = os.environ.get('API_KEY') | |
NATION = os.environ.get('NATION') | |
params = {"access_token": API_KEY} | |
if API_KEY is None: | |
raise SystemExit("Missing API_KEY environment variable. Please set your NationBuilder API key.") | |
if NATION is None: | |
raise SystemExit("Missing NATION environment variable. Please set your NationBuilder slug.") | |
# A simple helper to build the uri of the desired endpoint | |
def endpoint(endpoint): | |
return 'https://' + NATION + ".nationbuilder.com/api/v1/" + endpoint | |
person = {'person':{ | |
'first_name': 'Bozo', | |
'last_name': 'Clown', | |
'email': 'bozo@clown.com' | |
}} | |
response = requests.post(endpoint('people'), params=params, json=person) | |
assert 201 == response.status_code, "Could not create person!" | |
id = repr(response.json().get('person').get('id')) | |
#update the person with a birthday | |
birthday = {'person': {'birthdate': '1984/02/23'}} | |
response = requests.put(endpoint('people/'+id), params=params, json=birthday) | |
assert 200 == response.status_code, "Could not update person!" | |
#remove person | |
response = requests.delete(endpoint('people/'+id), params=params) | |
assert 204 == response.status_code, "Could not remove person!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment