Reputation: 181
I want to update custom_attributes of Intercom through PHP CURL.
I am passing user_id and email as parameter still getting this error. {"code":"400","message":"User email, user_id or anonymous_id must be supplied"}
try {
$postData = json_encode(array(
"user_id" => strval($userDetails["id"]),
"email" => $userEmail,
"custom_attributes" => ['unsubscribed_from_emails' => 'true']
));
$postHeader = [
'Authorization: Bearer <Access Token>',
'Accept: application/json',
'Content-Type: application/json -d'
];
$curl = curl_init("https://api.intercom.io/users");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $postHeader);
curl_exec($curl);
curl_close($curl);
} catch (Exception $e) {
error_log($e->getMessage());
}
Upvotes: 0
Views: 786
Reputation: 1424
As per php.net about the CURLOPT_POSTFIELDS:
This parameter can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.
https://www.php.net/manual/en/function.curl-setopt.php
But you pass a json instead.
Upvotes: 0