Recent searches
No recent searches
Can't create identities (PHP/CURL)
Posted May 26, 2023
Hello,
I'm using PHP/CURL to manage identities of my Zendesk contacts.
I can right now list users, identities and remove identities but I'm stuck when trying to create a new identity for an existing user.
My example (this is simplified) :
$dataAI = 'https://xxxxx.zendesk.com/api/v2/users/212121212112/identities.json';
$create = '{"identity":{"type":"phone_number","value":"+3312121212"}}';
Called like this :
curlWrap($dataAI, $create, "POST");
Here is the Curl function :
function curlWrap($url, $json, $action)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
switch($action){
case "POST":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
break;
case "GET":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
break;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/binary; charset=utf-8', 'Accept: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($output, true);
return $decoded;
}
Am I missing something ?
0
2
2 comments
Edouard PIGEON
Someone find a way to get this working : https://stackoverflow.com/questions/18387427/using-curl-to-post-json-with-php-variables
I add this line in the "POST" case of curlWrap function :
0
Eric Nelson
Glad you were able to find a solution! Let us know if you need anything.
0