简体   繁体   English

如何使用Form API在Hubspot中创建潜在客户?

[英]How to create a prospect in hubspot using the Form API?

I am trying to create a prospect in hubspot by submission of the form. 我正在尝试通过提交表单在hubspot中创建潜在客户。 Following is the code that i have written. 以下是我编写的代码。

<?php
    function send_lead() {
    $hubspotutk = $_COOKIE['hubspotutk'];
    $ip_addr = $_SERVER['REMOTE_ADDR'];
    $hs_context = array(
        "hutk" => $hubstoputk,
        'ipAddress' => $ip_addr,
         'pageName' => 'Test Form'
       );

    $hs_context_json = json_encode($hs_context);
    //Need to populate these varilables with values from the form.
    $str_post ="email=" . urlencode($_POST["email"])
                    . "&hs_context=" . urlencode($hs_context_json);  //Leave this one be :)'

    //replace the values in this URL with your portal ID and your form GUID
    $endpoint = 'https://forms.hubspot.com/uploads/form/v2/portal-id/form-id';
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
    @curl_setopt($ch, CURLOPT_URL, $endpoint);
    @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = @curl_exec($ch);  //Log the response from HubSpot as needed.
    @curl_close($ch);
    echo $response;

}
?>

I get an empty response. 我得到一个空洞的回应。 Can anyone tell me whats wrong with my code? 谁能告诉我我的代码有什么问题吗?

A response of 204 is received from Hubspot when the form submission is successful. 表单提交成功后,会从Hubspot收到204响应。 A 204 is a response with no content. 204是没有内容的响应。

Hubspot form api reference can be found here: http://developers.hubspot.com/docs/methods/forms/submit_form 可以在此处找到Hubspot表单api参考: http : //developers.hubspot.com/docs/methods/forms/submit_form

Spelling mistake in the variable name. 变量名称中的拼写错误。 Use $hubspotutk in the $hs_context array. $hs_context数组中使用$hubspotutk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM