We're thrilled to see all the great development going on with the NationBuilder API, and want to open this forum up for public feedback, helps and hints, questions and more. This resource is curated by the NationBuilder API Team - our goal is developers helping developers, so we definitely want to hear from you. You can also use the tags to rank posts. Thanks!
PUT to people API via PHP
When i do something link this in PHP:
$params = array(
'person' => array(
'email' => '[email protected]','home_address' => array('country' => 'Germany', 'zip' => '66666' ))
);
$header = array('Authorization:' => $token,'Content-Type:' => 'application/json', 'Accept:' => 'application/json');
$response = $client->fetch($baseApiUrl . '/api/v1/people/push?access_token=myaccesstoken', $params, 'PUT',$header);
print_r($response);
i get the following response
Array
(
[result] => Array
(
[code] => missing_parameters
[message] => Missing Parameters.
[parameters] => Array
(
[0] => person
)
[inner_error] => Array
(
[name] => Api::Error::MissingParameters
[message] => Missing parameters: person
)
)
[code] => 400
[content_type] => application/json
)
Whats wrong with the Parameters? Do i need to add something else to the Params?
submitted
Alexander, I sent you an email with a proposed solution; let me know if that works for you.
thanks, Arion Hardison
PUT request
We're making a request to an offsite domain, and when I making a PUT request to the offsite server via $.ajax, it looks as if the authenticity token is being concatenated to the end of the stringified JSON object - this obviously causes problems when our offsite server attempts to parse the JSON object, it finds a "&authenticity_token=..." which is not valid JSON.
It looks as if the check of how the authenticity token should be appended (I snooped around a bit in the minified liquid files) is a bit naive. Yes, we're sending up JSON, but best practice (http://stackoverflow.com/a/12693986 <http://stackoverflow.com/a/12693986>) is to stringify with $.ajax first. The authenticity token attachment logic incorrectly interprets the stringified JSON to be a query string.
I have solved this for the most part by preventing this event handler from firing by including the 'global:false;' option in the AJAX request. Thanks!
submitted
Hi Luke,
You should be able to stringify your JSON data in an $.ajax request, though it sounds like you were able to resolve this on your own by setting the global parameter to false. If you're still running into issues, however, you can send your examples to [email protected] and we'd be happy to investigate further.
FWIW, another developer seemed to encounter a similar error and was able to resolve by removing the accepts parameter: JSON/jQuery formatting for People create?
Deleting an address
How can I delete an address through the API? I have tried using the people/:id endpoint but if I pass an object with something like "home_address": null it doesn't do anything. If I pass an address object with all the components set to null (ie { "address1": null, "address2":null, etc. }) I can see from the main GUI that the components have indeed been blanked but there is still a "delete address" button, which suggests that the address still exists on the system albeit with blank components.
completed
When clearing out the address types (home_address, billing_address, registered_address, or mailing_address), you would need to pass empty strings and null with the request.
For example, you could use this curl with the PUT request on the People endpoint here:
curl -v -X PUT --header "Content-Type: application/json" --header "Content-Type: application/json" —data '{ "person": {"home_address": {"address1": "","address2": "","address3": "","city": "","county": null,"state": null,"country_code": "","zip": null,"lat": null,"lng": null,"fips": null,"street_number": null,"street_prefix": null,"street_name": null,"street_type": null,"street_suffix": null,"unit_number": null,"zip4": null,"zip5": null,"sort_sequence": null,"delivery_point": null,"lot": null,"carrier_route": null}}}'https://NATIONSLUG.nationbuilder.com/api/v1/people/PERSONID?access_token=TOKEN
Make sure to change NATIONSLUG to the slug of your specific nation, PERSONID to the ID of the person you are looking to update in your database and change TOKEN to your API token that you can get through Settings > Developer > API Token.
If you continue to have problems with clearing out the address fields, let us know and we would be happy to help through email at [email protected]
NOTE - this is not a solution for redefining a primary address as whilst you will be able to empty the address you will not be able to re-add that address as the “primary” designation remains even once the address no longer has data in it.
Set address used as primary address
Using the API, how can I update which address is currently used as the primary address? e.g. mailing, home, billing, ... It would also make sense if the person object included which address is currently set as the primary address. This is helpful to know which address to update.
submitted
It isn't possible to change which address is the primary address via the API. If it is not set manually in the control panel, the primary address is set automatically to the first present address in this hierarchy:
1. home
2. registered
3. billing
4. work
5. mailing
6. user-submitted
7. Twitter
If you wish a different address to be the primary for a group of records, you would need to run a batch update in the control panel.
Cancelling the recurring donation
How to cancel a recurring donation? By looking at API documentation I've noticed that each donation has two fields: recurring_donation_id (which is not writable) and canceled_at.