dtp791357 2018-10-25 11:17
浏览 52
已采纳

内部通信API CURL获取错误“代码”:“400”,“消息”:“必须提供用户电子邮件,user_id或anonymous_id”

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());
            }
  • 写回答

1条回答 默认 最新

  • duanluan2047 2018-10-25 11:22
    关注

    As per php.net about the CURLOPT_POSTFIELDS:

    This parameter can either be passed as a urlencoded string like 'para1=val1&para2=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.

    http://us2.php.net/manual/en/function.curl-setopt.php

    But you pass a json instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据