Trying to create php code to add person, but it’s not working. Here’s the code (removed my api token and pd account for security)…I have the API working for other actions but not this one. Thanks in advance.
<?php // Pipedrive API token $api_token = 'my api token'; // Pipedrive company domain $company_domain = 'my domain'; // Name of the new person $person = array( 'name' => 'foobar', ); $url = 'https://' . $company_domain . 'pipedrive.com/api/v1/persons?api_token=' . $api_token; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); echo 'Sending request...' . PHP_EOL; $output = curl_exec($ch); curl_close($ch); // Create an array from the data that is sent back from the API // As the original content from server is in JSON format, you need to convert it to PHP array $result = json_decode($output, true); // Check if an Organization ID came back, if did print it out if (!empty($result['person']['id'])) { echo 'person added successfully! ' . PHP_EOL; }Hi @Brian_Blonowicz
Tested yours out and it didn’t work indeed. Re-tried it with the following code and it worked. Can you try this one out and see if it works for you?
<?php
// Pipedrive API token
$api_token = ‘enter yours’;
// Pipedrive company domain
$company_domain = ‘enter yours’;
// Name of the new organization
$data = array(
‘name’ => ‘John Doe’
);
$url = ‘https://’.$company_domain .’.pipedrive.com/api/v1/persons?api_token=’ . $api_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
echo ‘Sending request…’ . PHP_EOL;
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output, true);
if (empty($result[‘data’])) {
exit(‘Adding failed’ . PHP_EOL);
}
// Check if an Person ID came back, if did print it out
if (!empty($result[‘data’][‘id’])) {
echo 'Person added successfully! ’ . PHP_EOL;
}
Thank you so much Elina! That worked!
Now I’m trying to update a custom field. I can update existing fields like postal_address, but I have a custom address called property address I need to update too. Any thoughts?
Hi @Brian_Blonowicz, for updating different fields, you need first to know the ID of that field, and for custom fields, it’s tied to the entity type, e.g., if the property address field is tied to a Deal, you’ll need to call the DealFields endpoints. We also have a sample guide to follow along and an overview page for custom fields - maybe these can assist you further. In any case, if the problem continues, let me know
I was able to get this to work. Thanks!
Awesome! Glad to hear