无法创建身份(PHP/CURL)
你好,
我使用PHP/CURL来管理我的Zendesk联系人的身份。亚博
我现在可以列出用户,身份和删除身份,但当我试图为现有用户创建一个新的身份时,我卡住了。
我的例子(这是简化的):
$dataAI = 'https://xxxxx.亚博zendesk.com/api/v2/users/212121212112/identities.json';
创建美元= '{“身份”:{“类型”:“phone_number”、“价值”:“+ 3312121212”}}';
这样叫:
curlWrap($data, $create, "POST");
下面是Curl函数:
函数curl ($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);
开关(行动){
“后”:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
打破;
例“获得”:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
打破;
“把”:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
打破;
“删除”:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
打破;
默认值:
打破;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/binary;charset=utf-8', 'Accept: application/json;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);
返回$解码;
}
我错过什么了吗?
-
有人想办法让它工作:https://stackoverflow.com/questions/18387427/using-curl-to-post-json-with-php-variables
我在curlWrap函数的"POST" case中添加了这一行:
curl_setopt(ch美元CURLOPT_HTTPHEADER,数组(“application / json内容类型:,的内容长度:.strlen(json美元),“X-HTTP-Method-Override:文章”));
-
嗨,爱德华,
很高兴你能找到解决办法!如果你需要什么就告诉我们。
请登录留下评论。
2的评论