【问题标题】:How to post form data for new person to Pipedrive (API) via REST如何通过 REST 将新人的表单数据发布到 Pipedrive (API)
【发布时间】:2014-06-27 11:04:37
【问题描述】:

这是不起作用的表格:

<form action="https://api.pipedrive.com/v1/persons" method="post">   

    <!-- These hidden fields have valid values, just not shown here -->
    <input type="hidden" name="owner_id" id="owner_id" value="my-id" /> 
    <input type="hidden" name="org_id" id="org_id" value="my-company-id" /> 
    <input type="hidden" name="api_token" id="api_token" value="my-api-key" /> 
    <input type="hidden" name="stage_id" id="stage_id" value="35" /> 

    <b>Name</b><br/>
    <input type="text" name="name" id="name" id="name"/>
    <br/><br/>

    <b>E-mail</b><br/>
    <input type="text" name="email" id="email" id="email"/> 
    <br/><br/>

    <b>Arrival</b><br/>
    <input type="text" name="2fdf1284127d702e42595ce20bd8ffdf60763105" id="2fdf1284127d702e42595ce20bd8ffdf60763105"/>
    <br/><br/>

    <b>Departure</b><br/>
    <input type="text" name="2492a5afed2a9cb7948d6a22135fd4dd80de200c" id="2492a5afed2a9cb7948d6a22135fd4dd80de200c"/>
    <br/><br/>

    <b>Message</b><br/>
    <textarea style="width:300px; hight:70px;" id="7433280b87ffc7c1e3fd615eb35526273bcea6cf" name="7433280b87ffc7c1e3fd615eb35526273bcea6cf"></textarea>     
     <br/><br/> 
    <input type="submit" value="Remitir"/> 
</form>

提交后,返回如下响应:

{"success":false,"error":"Organization not found.","data":null,"additional_data":null}

通过 REST 成功添加新人缺少什么?

Here is the API:https://developers.pipedrive.com/v1

非常感谢您的解决方案。

【问题讨论】:

  • 这个 API 有文档吗?
  • API是developers.pipedrive.com/v1,但是我没有成功使用过。
  • 嗨@iamtoc 请帮助我如何做到这一点

标签: json rest pipedrive-api


【解决方案1】:

你可以这样做

<script language="javascript" type="text/javascript">
    function pDriveIntegration()
    {
       var url = "https://api.pipedrive.com/v1";
       var rsrc_deals = "/deals";
       var api_token = "YOUR_API_TOKEN";
       var deal
Json = '{' + '"title":"' + name + '","org_id":"?"' +
                    ',"value":"0"' + ',"currency":"GBP"' + ',"stage_id":"?"' + 
',"visible_to":"?"' + ',"status":"open"' + '"}';


        var xhrDeal = new XMLHttpRequest();
        xhrDeal.onreadystatechange = function()
        {
            if (xhrDeal.readyState == 4 && xhrDeal.status == 201) {
                var obj = JSON.parse(xhrDeal.responseText);
                var deal_id = obj.data.id;
            }
        }
        xhrDeal.open("POST", url + rsrc_deals + "?" + "api_token" + "=" + api_token, false);
        xhrDeal.setRequestHeader("Content-type", "application/json");
        xhrDeal.send(dealJson);

</script>
</head>
<body>

<form ...........>


<input type="submit" onclick="pDriveIntegration();"


</form>

因此您需要 AJAX。即使可以仅使用 HTML 表单来执行此操作,您也必须对 JSON 进行编码以与帖子一起发送。老实说,我试过了,但我总是在任何浏览器中遇到一些错误。

我注意到这根本不安全,因为有人能够看到您的源代码并通过浏览器获取您的 API_TOKEN。我的意思是有人可以获取您的所有信息(我转向其他解决方案,而不仅仅是使用 HTML 和 AJAX)。

但无论如何,了解你需要的一切都是一个好的开始。

我还建议考虑“人”。例如,在创建新交易之前,我会找到该人。如果他/她存在,我不会创建它,我会得到它的 id,然后我会进行交易。

但是,在另一种情况下,如果该人不存在,我首先创建一个人。之后,我会在 Deal 上使用它的 id。

希望对你有用。

再见

【讨论】:

  • 这完全不安全,因为用户可以看到 api 密钥。最好是使用下面的答案并使用 ajax 发布到那里。然后用户将无法看到 api 密钥
【解决方案2】:

使用php,会是这样的:


// ================================== //
// API token
// ================================== //
$api_token = 'xxxxxxxxxxxxxxxxxxxxxx';

// ================================== //
// FORM INPUT CAPTURE
// ================================== //
$name = $_POST['inputname'];
$phone = $_POST['inputphone'];
$mail = $_POST['inputmail'];

// ================================== //
// PERSON'S API Key fields' Array values
// ================================== //
$persons = array(
    'name' => $name,
    'email' => $mail,
    'phone' => $phone
);

// ================================== //
// API PERSONS domain
// ================================== //
$url1 = 'https://personalpipedriveadress.pipedrive.com/v1/persons?api_token=' . $api_token;

// ================================== //
// CURL access
// ================================== //
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $persons);

echo 'Sending USER request...' . '<br>';

$output1 = curl_exec($ch1);
curl_close($ch1);

// ================================== //
// API array data convert to JSON format
// ================================== //
$result1 = json_decode($output1, true);

// ================================== //
// Check if an ID came back and print it
// ================================== //
if (!empty($result1['data']['id'])) {
    echo 'Person was added successfully!' . '<br>';
}
else {
    echo 'ERROR adding person';
}


【讨论】:

  • api_token 必须从您的帐户设置中获取; // API 域必须与在 Pipedrive 注册的用户名一起使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 2020-12-07
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
相关资源
最近更新 更多