Created
July 28, 2014 22:51
-
-
Save ArionHardison/4828c259dc0f8d4ab2af to your computer and use it in GitHub Desktop.
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
<?php | |
//put in your nation slug and token | |
$url ="https://<your slug>.nationbuilder.com/api/v1/people?access_token=<token>"; | |
$data = array( | |
'person' => array( | |
'email' => "[email protected]", | |
'last_name' => "Bob", | |
'first_name' => "Smith", | |
'sex' => "M", | |
'employer' => "Dexter Labs", | |
), | |
); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, '10'); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, | |
array("Content-Type: application/json","Accept: application/json")); | |
$json_data = json_encode($data); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); | |
$json_response = curl_exec($ch); | |
curl_close($ch); | |
$response = json_decode($json_response, true); | |
print_r($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might need to add
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
to your cURL options for this example to work in some environments.Thanks for the example!