使用自定义提交的php创建GetResponse API联系人

时间:2017-12-04 12:11:01

标签: php getresponse

我正在尝试使用GetResponse API创建与自定义字段的新联系人,这是我的代码:

$headers = [
                    'Accept: application/json',
                    'Content-Type: application/json',
                    'X-Auth-Token: api-key '.$model->getresponse_key
                ];

                $curl = curl_init();
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_URL, 'https://api.getresponse.com/v3/contacts');
                curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
                curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([ 'name' => $user->full_name, 'email' => $user->email, 'campaign' => [ 'campaignId' => $model->getresponse_campaign ] , 'customFieldValues' => [['customFieldId' => 'tel', 'value' => [$user->phone]]]], JSON_FORCE_OBJECT));
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
                $result = curl_exec($curl);
                $result2 = json_decode($result);

我收到了这个回复:

object(stdClass)#174 (7) {
      ["httpStatus"]=>
      int(400)
      ["code"]=>
      int(1000)
      ["codeDescription"]=>
      string(78) "General error of validation process, more details should be in context section"
      ["message"]=>
      string(34) "Custom field by id: tel not found "
      ["moreInfo"]=>
      string(49) "https://apidocs.getresponse.com/en/v3/errors/1000"
      ["context"]=>
      array(0) {
      }
      ["uuid"]=>
      string(36) "b5a2465b-08df-4cdd-80c8-**********"
    }

我真的不知道该代码可能出现什么问题,请帮忙。

1 个答案:

答案 0 :(得分:0)

You can use this - 

$response = new GetResponse($access_token);
$campaign = array('campaignId'=>123);
$params = array(
    'email' => $email,
    'campaign' => $campaign,
    'name' => $fname.' '.$lname,
);
$result = $response->**addContact**($params);
$status = $response->http_status;
print_r($status);