我该如何解决Hubspot API探针

时间:2019-12-27 06:34:43

标签: php rest api hubspot hubspot-crm

我已添加此PHP代码以在Hubspot CRM联系人列表上创建自定义属性。 每次我都尝试过,但没有成功。尽管没有错误,但没有显示在HubSpot联系人列表中。该代码有什么问题,请告诉我。谢谢

    $company='demo-content1';
    $fname='demo-content1';
    $lname="Demo-content";
    $phone='demo-content1';
    $email='demo-content1';
    $address='demo-content1';
    $city='demo-content1';
    $code='demo-content1';
    $info='demo-content1';
    $totalsession='demo-content1';
    $totalcost='demo-content1';
    $radio1='demo-content1';


    $contact_data = array(
        "fname" => $fname,
        "lname" => $lname,
        "email" => $email,
        "phone" => $phone,
        "info" => $info,
        "code" => $code,
        "city" => $city,
        "radio1" => $radio1,
        "address" => $address,
        "totalsession" =>$totalsession,
        "company" => $company
    );

    $ans_hubspot = new ans_hubspot();
    $ans_hubspot->contact_create($contact_data);
    $ans_hubspot->list_assign_contact("2", $contact_data["phone"]);




class ans_hubspot{
    private $hapikey = "2c2f5d4c-c85b-4e27-9942-898636c9d624";

    function list_assign_contact($lid, $phone){
        (object)$arr = array(
            "phone" => array($phone)
        );
        $post_json = json_encode($arr);
        $endpoint = 'https://api.hubapi.com/contacts/v1/lists/'.$lid.'/add?hapikey=' . $this->hapikey;
        $this->http($endpoint,$post_json);
    }   


    function list_create($list_name){
        $arr = array(
            "name" => $list_name,
            "dynamic" => false,
            "filters" => array(
                array(
                    (object)array(
                        "operator" => "EQ",
                        "value" => "@hubspot",
                        "property" => "twitterhandle",
                        "type" => "string"
                    )
                )  
            )
        );
        $post_json = json_encode($arr);
        $endpoint = 'https://api.hubapi.com/contacts/v1/lists?hapikey=' . $this->hapikey;
        $this->http($endpoint,$post_json);
    }

    function contact_create($contact_data){
     $arr = array(
        'properties' => array(
           array(
                'property' => 'acceptance',
                'value' => "Undecided"
            ),
            array(
                'property' => 'num',
                'value' => $contact_data["totalsession"]
            ),
            array(
                'property' => 'company',
                'value' => $contact_data["company"]
            ),
            array(
                'property' => 'address',
                'value' => $contact_data["address"]
            ),
            array(
                'property' => 'city',
                'value' => $contact_data["city"]
            ),
            array(
                'property' => 'session',
                'value' => $contact_data["radio1"]
            ),

            array(
                'property' => 'code',
                'value' => $contact_data["code"]
            ),
            array(
                'property' => 'info',
                'value' => $contact_data["info"]
            ),
            array(
                'property' => 'phone',
                'value' => $contact_data["phone"]
            ),
            array(
                'property' => 'email',
                'value' => $contact_data["email"]
            ),
            /*array(
                'property' => 'lastname',
                'value' => $contact_data["lname"]
            ),*/
            array(
                'property' => 'firstname',
                'value' => $contact_data["fname"]
            )

        )
    );

        $post_json = json_encode($arr);
        $endpoint = 'https://api.hubapi.com/contacts/v1/contact?hapikey=' . $this->hapikey;
        $this->http($endpoint,$post_json);
    }

    function http($endpoint,$post_json){

        $ch = @curl_init();
        @curl_setopt($ch, CURLOPT_POST, true);
        @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
        @curl_setopt($ch, CURLOPT_URL, $endpoint);
        @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = @curl_exec($ch);
        $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curl_errors = curl_error($ch);
        @curl_close($ch);
        return $response . "<hr>";

    }
}

0 个答案:

没有答案