Hello, I am trying to create an application with People Create Endpoint and the PHP API.
'Get Peoples' works perfect but when I try to add a new person in my Nation, the problems begin.
My token is valid, because I tested it with the new API Explorer tool.
My example with GET is:
$ token = ' MyToken ';
$ baseApiUrl = ' https://johndoe.nationbuilder.com ' ;
$ client -> setAccessToken ($ token );
$ response = $ client -> fetch ( $ baseApiUrl '/ api/v1/people /'. )
print_r ( $ response );
This shows all the Peoples in my nation.
And this is the example I'm using with POST:
$ token = ' MyToken ';
$ baseApiUrl = ' https://johndoe.nationbuilder.com ' ;
$ client -> setAccessToken ($ token );
/ *
$ data = array (
'person ' = > array (
'email' = > ' [email protected] ' , " last_name " = > " Smith ", " first_name " = > "Bob"
)
) ;
$ data_string = json_encode ( $ data );
$ response = $ client -> fetch ( $ baseApiUrl '/ api/v1/people / ', $ data_string , "POST" . )
print_r ( $ response );
I'm not getting any response neither in the browser nor in the curl_request_info file.
What is wrong with my code?
I'm using Ryan Morgan's library ( https://github.com/RyanMorgan/PHP-OAuth2 ) .
I hope someone can help me or show me one example of how to do a POST Request for People correctly?
Thank you very much!
Share this post
Showing 7 reactions
Sign in with
Social Benchers
Social Benchers
Certified Architect
Certified Expert
Certified Developer
Social Benchers
Social Benchers
Certified Architect
Certified Expert
Certified Developer
You Have To insert like that
$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);
Note: most important check in your client.php file in execution function to pass parameters in it … after that you can insert in it ….
thanks
did someone get the right response ?? I have the same problem with the same library.
Thanks in advance