Skip to content

Instantly share code, notes, and snippets.


speg/ Secret

Created Nov 8, 2014
What would you like to do?
NationBuilder Person API
# This python script requires the requests HTTP library
# See for more information.
import os
import requests
except ImportError:
raise SystemExit("Missing requests library -")
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 + "" + endpoint
person = {'person':{
'first_name': 'Bozo',
'last_name': 'Clown',
'email': ''
response ='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