Skip to main content

API Developers Forum

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!

Please check your e-mail for a link to activate your account.
Sort by

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?

 

 

 

13 reactions

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!

4 reactions

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.

Official response from

3 reactions

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.

6 reactions

Liquid error: undefined method `total_pages' for #