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!
Does Nationbuilder have a Rails 4 API gem in the works?
/events/:id has Contact.phone missing 1st number
Ive tested this in the API explorer as well as with the following command line invocation:
curl -X GET --header "Content-Type: application/json" --header "Accept: application/json" https://agv.nationbuilder.com/api/v1/sites/agv/pages/events/\?id\=...\&access_token=...
Both produce contact phone numbers with the first number missing
e.g. 0411222333 is given as 411222333
Viewing the event via http://victoria.greens.org.au/ocean_grove_doorknock_and_snack
we see that the correct, full phone number is displayed.
Can you please fix this?
Recording Pledge Data via the API
I'm working for a non-profit that is running a pledge drive, and has pledge form on its website. Is there any way we can move pledge data into NationBuilder via the API? I don't see pledges referenced anywhere in the documentation.
How to set the featured content
I'm trying to import a few Wordpress sites using the API. On each of them every blog post has a header image. The equivalent in NationBuilder would be to add a signle featured content slider to each page, but I don't see anything in the API to do this. Am I missing something? If this can't be done, is there a way to set HTML before the content_before_flip?
How to get client id and api secret
How to get client id and api secret
Steps 3 and 4 of our API Quickstart guide describe how to obtain a client ID and API access token:
Subscribe to list widget
I want to add a box to my site that allows users to sign up for a mailing list that we are now migrating to NationBuilder.
My site is Python/Django. I have this already set up with Mailchimp.
The Python Quickstart doc doesn't explain what the variables 'code' or 'REDIRECT_URI' are or how they should function in step 4.
This should be pretty basic functionality. Am I missing something? Is there a simpler way to implement this?
Brett, for a single-nation use, just use an app test token - you can find that in your nation's control panel under Settings > Apps.
Deleted/Merged webhook
This is needed to ensure proper cotnact synchronization between an external database and NationBuilder. You can delete from NB, but no webhook fires when data is removed or merged.
People API Update endpoint always errors
I'm using the Update endpoint, with the request straight from the documentation:
curl 'https://[nation].nationbuilder.com/api/v1/people/[id]?access_token=[token]' -X PUT -H 'Content-Type: application/json' -d '{"person":{"first_name":"Joe","email":"[email protected]","phone":"303-555-0841"}}'
I receive this response:
{"code":"server_error","message":"You have encountered a server error."}
This is after creating a record using the People Create endpoint, and verifying the record is available with the People Show endpoint.
Any help appreciated.
People API fails to create address resources
I'm using the Create endpoint, with the request straight from the documentation:
curl 'https://[nation].nationbuilder.com/api/v1/people?access_token=[token]' -X POST -H 'Content-Type: application/json' -d '{"person":{"email":"[email protected]","last_name":"Smith","first_name":"Bob","sex":"M","employer":"DexterLabs","party":"P","registered_address":{"state":"TX","country_code":"US"}}}'
I receive a full response body, but with
"registered_address":null
Any help appreciated.
Pulling statistics from the API
I'm trying to display some data from our campaign on a dashboard (http://shopify.github.io/dashing/) by pulling the information through the API. I'm able to get the total number of people from the People index resource, but can't figure out how to do anything more complicated, such as the number of people with a support level of 1 or 2. I have a filter in my control panel for it but the closest I can get would be to add those people to a list and query that, which isn't dynamic.
Any thoughts or pointers?
Thanks.
Donation Synchronization, and Donation Search Endpoint
For my organization's use case, we need a synchronization of all donation records, in order to produce financial reports, and for other uses. This requires high reliability of the synchronization process.
- Webhooks provide a synchronization potential with the downside that, like webhooks of other internet-based services, there is almost no feedback about webhook invocation failures. This makes not meet the requirements of our use case.
- Querying the table of donation records as a replacement, or a verification procedure, of the webhook method would be workable. However, since donations do not currently provide a search endpoint with an "updated_since" parameter, this creates the problem of having to download the whole donation table each time a synchronization is required. This limitation makes the method virtually unusable for production employment in our use case.
Could you lift any of these limitations, or is there another way to solve this problem. Again, we have the legal necessity of not missing any records, or misrepresenting any record fields.
Thanks,
--
Pav
People Update server error
I'm trying to update a supporter record and running in to a 500 error.
I did a PUT request to
https://[nation].nationbuilder.com/api/v1/people/[id]?access_token=[token]
using the data:
{"person":{"first_name":"Jane","last_name":"Smith","phone":"123-456-7890"}}
This is the response:
HTTP/1.1 500 Internal Server Error
Date: Wed, 09 Apr 2014 14:38:59 GMT
Server: Apache/2.2.22 (Ubuntu)
X-UA-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache
Nation-RateLimit-Limit: 15000
Nation-RateLimit-Remaining: 14978
Nation-RateLimit-Reset: 1397088000
X-Request-Id: 61ca028a58830a98d0c83ce60c18d079
X-Runtime: 0.532239
X-Rack-Cache: invalidate, pass
X-Powered-By: Phusion Passenger 4.0.23
Status: 500 Internal Server Error
Vary: Accept-Encoding
Content-Type: application/json
Via: 1.1 nationbuilder.com
Connection: close
Transfer-Encoding: chunked
{"code":"server_error","message":"You have encountered a server error.","inner_error":{"name":"NoMethodError","message":"undefined method `strip' for nil:NilClass"}}
The same data POSTed to the create endpoint successfully created a supporter, and I'm using the same function to PUT tags.
Any ideas what could be causing this?
People Create Endpoint and PHP.
Set date when awarding social capital
I would like to be able to set the date when awarding social capital. More importantly I would like to do this through the API.
The reasoning for this is that if we manually award SC for somebody who volunteered to work a shift at one of our events, we would like the date that the SC was awarded to be the same date as the event. We actually have a backlog of SC that I was planning on importing using the API and just realized that I can't set the award date.
Events API "guests_count" parameter clarification
Posted this on the Events API page (http://nationbuilder.com/events_api) but thought I should post here as well:
For the guests_count parameter, what is the API referencing? When you create an event, you have the option to do a simple RSVP and include +1s. However, if you have ticket sales, you purchase a number of tickets. Does guest_count reference +1s or number or tickets, or both? Ideally, it would great if it’s both!
Test Token Example
You have great examples on how to navigate the minefield that is OAUTH, but now that you have test tokens, I'd like to see some simple example code on how to use the test token (python/php or even curl).
Thanks
Dennis
curl https://[slug].nationbuilder.com/api/v1/people/search?access_token=[my test token here] -X GET -H “Content-Type: application/json” -d ‘{"first_name":"Arion"}’
Searching people returns invalid json format error
I am searching people using this url:
https://malaysia.nationbuilder.com/api/v1/people/search?access_token=my_tokken
with header "Content-Type: application/json" and with following request body:
{"first_name":"abc"}
but it gives me error that json format is invalid
You can accomplish this search with a cURL command wrapping your JSON into the URL. See below for the command you can run in Terminal:
curl https://malaysia.nationbuilder.com/api/v1/people/search?access_token=[my test token here] -X GET -H “Content-Type: application/json” -d ‘{"first_name":"abs"}’
How to save access token in PHP?
I've tried saving the access token as a key/value pair in the $_SESSION variable, but if
a) I encrypt it and then save it, on the next page or request, it has changed or
b) I don't encrypt it and save it as a string, it is deleted from $_SESSION on the next page.
What am I doing wrong here? I need to make multiple requests in sequence and have a feeling I shouldn't need to ask for a new access token with each one. Thanks!
Can you paste the code?
I have a few questions here
1) Why are you encrypting the access token?
2) When you say "save" you just as a session variable or are you saving to a DB?
3) How are you saving it to $_SESSION and do you have this issue with any other variables? If so check your PHP version because $_SESSION and other register globals were deprecated in 5.3 and removed in 5.4
I would guess you are doing something like (see below)
<?php
session_start();
$_SESSION['token']=<access token here>;
?>
If you are losing your the value on the next page perhaps you are not passing a session identifier and calling session_start which would cause a new session to start.
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?
Alexander, I sent you an email with a proposed solution; let me know if that works for you.
thanks, Arion Hardison
Missing membership fields in People API
I want to synchronise our civicrm membership records with NationBuilder. But the People API does not have any fields for membership level, start or end dates.
Any chance in including every possible People field in the People API?
David, thanks for your suggestion - and yes, we're working on a massive expansion to the People API fields that should address your needs. We'll shoot you an email when that goes live.
Limitations with the write endpoint of the Donations API
The new write endpoint has a few limitations that make it difficult to implement a good external donations solution and track the donations back in Nation Builder:
1) It does not allow donations to be assigned to an existing supporter, but instead creates a new user for every donation. Ideally we'd be able to pass a signup id in the initial payload, which would then assign the donations.
2) We have not been able to write any donation types other than CASH (such as Credit Card), which means they are recorded as "FAILED" and do not show up in reporting.
3) There are no options to write recurring donations and have them show up in /admin/signups/{id}/donations/recurring. This means we cannot effectively build an external recurring donations system and track that back through Nation Builder.
1-2 are priorities for us to be able to effectively use the API for our apps, any idea when these options may be supported?
Scott, thanks for your feedback. 1 and 2 sound like possible bugs - can you send us information on which nation you were working on and cURL commands and response bodies for us to review to [email protected]? Our bug reporting tips are here.
I'm also looking into the feasibility of your request for recurring donations to be handled differently.
How to use JSONP with the API?
I'm trying to call the people api through AJAX using jquery but the response doesnt seem to have a callback wrapper, which causes an error. here is some sample code:
data = {
"access_token" : token
};
$.ajax({
url: peopleIndexUrl,
type: "GET",
cache: false,
data: data,
dataType: 'jsonp',
success: function(data,textStatus,jqXHR){
console.log(data);
},
error: function(jqXHR,textStatus,errorThrown){
console.log(errorThrown);
}
});
}
The call does seem to go through fine. Perhaps I have to change the callback? Thanks.
Eric, JSONP is supported for our API endpoints with the exception of stuff like the /oauth/token endpoint. You should be able to use it with endpoints like /api/v1/people
You also want to wrap your calls in JSONP. So:
https://yournation.nationbuilder.com/api/v1/people.jsonp
not,
https://yournation.nationbuilder.com/api/v1/people
If you continue to run into trouble, you can email us a text file with http request and response samples, using something like www.runscope.com, to [email protected].
error "nation_not_found"
I followed the PHP API Quickstart guide http://nationbuilder.com/php_quickstart and was able to easily obtain an access token. However, when I am trying to use the API in any way I get the following error response:
Array ( [result] => Array ( [error] => nation_not_found [message] => The nation identified by this request was not found. ) [code] => 404 [content_type] => application/json )
My nation is safestreets.nationbuilder.com, is there a setting I have to enable in order to use the API? Thanks.
Eric, the nation slug for safestreets was previously schoolmeals - you'll be able to use the API with the original name.
Theme API to Support Easy Theme Creation / Updates
Page Attachments API question.
Trying to upload a file with http://nationbuilder.com/page_attachments_api thru the oauth library, and getting error that the request uri is too long. I used encoder such as http://www.freeformatter.com/base64-encoder.html and got a ridiculously long string.
content - Base 64 encoded representation of the file, with standard RFC 4648
Am I doing something wrong? Does "representation of the file" means an encoded version of the file? or it means url to the file or some other kind of representations?
Any helps/hints are appreciated.
Thank you for your question.
In this case, you want to include the payload in the POST body as JSON, not in the URI as a query parameter. Although it might seem like both styles are equivalent, URI query parameters are more restrictive.
How does one create a sub page of a page through the API
There doesn't seem to be a way to either create pages as sub pages through the api or to attach existing pages to other pages as sub-pages.
Any help would be appreciated.
Thanks,
Steve
Steve, parent/child page relationships are not presently represented in the API. We'll review adding those parameters.
I get a 500 error when trying to add a page attachment to a blog
When I hit the following url:
https://mysitename.nationbuilder.com/api/v1/sites/mysitename/pages/blog/attachments?access_token=mytoken
with the data:
{"attachment":{"filename":"flower-tiny.jpg","content_type":"image/jpeg","content":"/9j/4AAQSkZJRgABAQEASABIAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQA\nAAABAAAAGgAAAAAAAqACAAQAAAABAAAADKADAAQAAAABAAAADAAAAAD/2wBD\nAAEBAQEBAQEBAQEBAQEBAgMCAgICAgMCAwIDBAMEBAQDBAQEBQYFBAUGBQQE\nBQcGBgYHBwcHBAUICAgHCAYHBwf/2wBDAQEBAQIBAgMCAgMHBQQFBwcHBwcH\nBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwf/\nwAARCAAMAAwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQF\nBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJx\nFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdI\nSUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKj\npKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx\n8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QA\ntREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHB\nCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldY\nWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmq\nsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6\n/9oADAMBAAIRAxEAPwD5/wD+CUf/AAS4/wCCd3xc/Ym+FHjPxj8L/G3xj+M/\nxomsLPVneyj1SXQJLuW4iF8EjdFtNNhGTJM25xhSc7QB/ON/wVV/Yag/Ys/b\nB8X/AAh8NadeaZ4TvbG31rSYGZ7oR2s7yxgLIwBdS0DkZ6ZK5O2vPf2SP+Cj\n37Uv7HnhrxV4Y+CnivSNM0/XIiu69sheSWYw5IgYsPLBbaxHIJRcjHB+VPjL\n8dPiv+0B8QNa+KHxd8a6x4y8ba8V+0Xlw+07V+7GqrhUUZOAAByT1JNeFjci\nxeT18HQyvHSlhGqlSsq8Yzqyqza5VCpHltSpWnGMbK8XC65ouT+yzzD08Vle\nAxNTESdSPNBQjTpwhbTmcmm5Tle1m0t5O+tj/9k=\n","updated_at":"2014-01-03T11:19:23-06:00"}}
I get a 500 error. Any way I can get this to work?
Thanks,
Steve
It may be that you don't have a page with the slug "blog" on your site. The Page Attachments API POST endpoint is looking for a slug, not a page type. If you need more help on this issue, please email [email protected]. Thank you!
PHP Webhook Listener
Make a php file on your server and create a webhook to point to it. When data is sent to the page, it will send you an email with the data. Make sure to change the email address before using.
Using OAuth2 access tokens with the People API
We are trying to use the http://nationbuilder.com/people_api with the Push endpoint to create new donors in the NationBuilder system from our external website. Basically when we process a new transaction we want to record the person in NationBuilder using the API. Obviously asking the donor to approve this action as part of the donation process is a pretty strange, so I'm a bit puzzled by the use of OAuth2 for this use case.
I have been following the documentation here to do the development: http://nationbuilder.com/api_quickstart
I've managed to get things working in PHP as per this guide: http://nationbuilder.com/php_quickstart
It seems we need to manually approve the application to get access in order to capture an access token which we can then use to post information to NationBuilder. Am I taking the right approach here? Should I be storing the access token server side to use later down the track for all our API requests? What happens when the access token expires?
Sebastian, the authorization is handled on a per-nation basis, so you won't need donors to approve passing their information once you have an access token from the nation. Per the quickstart guide, you'll have a nation administrator authorize the app, you'll get a short-live code back, then exchange if for an access token. That token should be stored securely and can be used again and again to pass information back to the appropriate nation. It expires only if revoked - then you'd need to have your app authorized again by the nation.
People API Should Expose "Bad Email Address" field
Like the title says, the boolean flag for the "bad email address" exposed in the HTML UI should be available in the Person record returned. Is there another way to acquire and set this value ?
Update: This field was added to the People API on March 25. Thanks for your suggestion!
PUT Method on Blog Posts API Example
Hi, i am reading the "Create Endpoint" article in the API documentation guide. I can't make the Post request work.
Could you provide a php code where i can see how to create the body for the request?
I'm using this code:
$fetch = $client->fetch($baseApiUrl . '/api/v1/sites/johndoe/pages/blogs/1/posts/', $parameters = array($json_body), 'POST', array(
"Content-Type" => "application/json",
"x-li-format" => "json"
));
I get this message: "invalid_json".
Thanks in advance!!
Fernando, check out this PHP library.
API for managing Political/Social Capital?
Is there a plan to open up the ability to add/remove political capital from the API... this would allow us to add PC for external events outside of the NB site... which would be very powerful... not something we need now, but I can see us using this in the future... thanks...
Yes! We have a set of endpoints for managing Political Capital.
Is JSONP enabled in the API?
I'm attempting to using AngularJS to access the API using JSONP (eg ?callback=JSON_CALLBACK, via this ST question) and I'm getting a 404 when hitting the /oauth/token endpoint.
Is JSONP enabled? If so, what might I be doing wrong here?
Relevant code below:
$http.jsonp('https://my_nation.nationbuilder.com/oauth/token?callback=JSON_CALLBACK', {
method: 'POST',
data: {
client_id: 'CLIENT_ID',
redirect_uri: 'http://localhost:9000',
grant_type: 'authorization_code',
client_secret: 'SECRET',
code: 'CODE',
}
})
Cannot obtain auth token
I cannot get past step 4 of the quickstart: http://nationbuilder.com/api_quickstart
I've made sure that my client id, secret, redirect url and code are all accurate and up to date.
Request:
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --data '{"grant_type":"authorization_code", "client_id":"CLIENTID", "client_secret":"SECRET", "redirect_uri":"http://localhost:9000", "code":"CODE"}' https://DOMAIN.nationbuilder.com/oauth/token
Note: things in capitals have been redacted
Response:
{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}
Any thoughts as to what could be going on?
access tokens
Access tokens are described in our API quickstart guide.
Does the API allow access to the work address?
Many supporters have work addresses -- this is where the employer's address is stored when people give that info when making donations.
However, it appears that the webhooks API only pushes out a supporters' primary address? This is not explicitly confirmed in the docs but I've done some testing and think this is the case.
What's more confusing is whether or not this field is available via the REST api. The docs list every other address field. I'm wondering if this is a documentation omission, or if for some reason the work address isn't included?
Hi Brad,
We've updated webhooks (v4) to include work addresss, and made some updates to the API as well to make the included fields read/writeable via the People endpoint.
email api?
Any thoughts on an email API that could help supporters recruit others? For example, I want to start a recruiting drive where each supporter recruits at least two others. I'd like to create an app that allows people to enter a few emails, use default/editable text, and send emails out right from the page on their behalf.
Great suggestion, Bruce. We do intent to expose more communications features in the API - however, we don't presently have a timeline for this and have quite a lot of new features planned before communications. You may want to look into SendGrid's API, which we use for our mail services - you could build an email app using their tools and log new people and contacts back into NationBuilder using our existing calls.
Using webhooks with PHP
Autumn Welles with Richir Outreach posted up this helpful NationBuilder webhooks + PHP tutorial with example script earlier this year.
Issue with Space and / in People Tags search
Was building app that to search for for people with specific tags using api call : GET https://foobar.nationbuilder.com/api/v1/tags/tagname/people , but it returns code t=404(NOT FOUND) if tag tagname string contains space or "/". This was not expected as spaces and / characters do not seem create search problems in other Tag searches on Nationbuilder outide of the API.
Mark, note that commas have specific functionality in the native tagging feature (splitting a comma-separate value into multiple tags) - however, other punctuation in tags can be handled through the API with standard HTML URL encoding. Here's a helpful resource for the encoding for different characters, including spaces and forward slashes:
Request Date Field in Contacts API
As noted else where in support, Contacts apparently default to date the contact was entered, and don't allow option to edit date to that on which contact actually occurred. This, ought to be fixed generally, and the option to edit the date added to the Contacts API
Request an Activity Stream API
I would like an API to access the Activity Stream, as the Contacts API is only showing a portion of the communications relevant to a person. My present objective is simply to access the same information as is shown in the People dashboard in read only format.
Request Followups API
Would like an API to access followups set for a person (or all persons) and assigned to a user (or any user).
People API could be improved easily with access to party and priority level fields
Would like to have the party and priority level fields added to the People API
Priority and party fields are now available in the People API.
Ruby tips: Debugging, layout and documentation
Our CTO, Dan Walmsley, spotted these helpful tips from globaldev:
Civicrm synchronisation
Has anyone already written code to synchronise People data between NationBuilder and a Civicrm site, using the two APIs?
We need to do that between our existing membership database and our NationBuilder site. I'd be interested to hear of any experiences from those who have already tried to do that.
Additional PHP resources and simple PHP example app
We've been seeing a lot of PHP development on our APIs, and we're hopeful that the developers using that language will continue to add shared resources. With that in mind, Jason Johnston from our team wrote up this "uber basic" client: https://github.com/jhnstn/nb-php
And Ryan Morgan from Veracity Media added body support for POST/PUTing to this OAuth 2.0 wrapper: https://github.com/RyanMorgan/PHP-OAuth2
Note: These are resources provided on an as-is basis and are not supported by NationBuilder. We encourage developers to continue to add to them and to use GitHub's pull request and issue reporting features.
Getting data on fundraisers' goals and amounts raised so far
[
{
"id": 314,
"amount": "$10.00",
"succeeded_at": "2013-02-21T10:04:15-04:00",
"corporate_contribution": false,
"fec_type": "Contribution",
"donor": {
"id": 8472,
"first_name": "Sarah",
"last_name": "Kerrigan",
"email": "[email protected]"
},
"election": {
"cycle": "2013",
"period": "Primary"
}
}
]Ted, we've just released a major expansion of the People API that includes the fundraising flag, goals, amounts raised and more. You can review the docs on Github here: NationBuilder People API on Github
NationBuilder Ruby gem from the team at ActionSprout
If you're looking for a Ruby gem to help out your development efforts, ActionSprout's got one up on GitHub here.
