[英]Pipedrive API PUT and POST requests for Filters endpoint not working
我正在嘗試從Pipedrive API中提取特定日期范圍內的交易。 我可以通過使用所需日期范圍的API編輯(或創建/刪除)過濾器,然后在隨后的請求中傳遞該過濾器以拉動所有交易來完成此操作。
“交易”端點工作正常。 我的問題是,API似乎不喜歡我為“過濾器”端點傳遞的“ conditions”參數-僅在我使用cURL(在我自己的代碼中)或Postman的情況下。 如果我在API文檔中測試了“編輯過濾器”或“創建過濾器”端點,則當我將代碼中的JSON對象復制並粘貼到“ conditions”參數中時,它們均能按預期工作。 但是,如果我使用cURL或Postman,則PUT端點僅返回我正在編輯的過濾器而無需對其進行編輯,而POST端點將創建一個空條件的新過濾器。
這是我用於POST端點的PHP代碼:
$data = [
'name' => 'Custom date range',
'type' => 'deals',
'conditions' => '{
"glue": "and",
"conditions": [
{
"glue": "and",
"conditions": [
{
"object": "deal",
"field_id": "12449",
"operator": "=",
"value": "won",
"extra_value": "null"
},
{
"object": "deal",
"field_id": "12455",
"operator": ">=",
"value": "2017-03-01",
"extra_value": "null"
},
{
"object": "deal",
"field_id": "12455",
"operator": "<=",
"value": "2017-03-10",
"extra_value": "null"
}
]
},
{
"glue": "or",
"conditions": []
}
]
}'
];
$ch = curl_init("https://api.pipedrive.com/v1/filters?api_token=$apiKey");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json;"));
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
$response = curl_exec($ch);
這是“創建過濾器”端點的“條件”參數的描述:
“將條件過濾為JSON對象。它要求的最小結構如下:
{"glue":"and","conditions":[{"glue":"and","conditions": [CONDITION_OBJECTS]},{"glue":"or","conditions":[CONDITION_OBJECTS]}]}
將CONDITION_OBJECTS替換為以下結構的JSON對象:
{"object":"","field_id":"", "operator":"","value":"", "extra_value":""} or leave the array empty.
根據對象類型,您應該使用另一個API端點來獲取field_id。 您可以選擇五種對象:
"person", "deal", "organization", "product", "activity"
並且您可以使用以下類型的運算符,具體取決於您擁有的字段類型:
"IS NOT NULL", "IS NULL", "<=", ">=", "<", ">", "!=", "=", "LIKE '%$%'", "NOT LIKE '%$%'", "LIKE '$%'", "NOT LIKE '$%'", "LIKE '%$'", "NOT LIKE '%$'".
為了更好地了解過濾器的工作原理,請嘗試直接從Pipedrive應用程序中創建過濾器。”
POST端點的“條件”參數相同。 同樣,當我將那個大的JSON對象粘貼到API docs測試中時,兩個端點都可以正常工作-但不適用於我自己的代碼。 任何幫助,將不勝感激。
編輯:這是我從cURL獲得的“創建過濾器”端點的響應:
{#233 ▼
+"id": 60
+"name": "Custom date range"
+"active_flag": true
+"type": "deals"
+"temporary_flag": null
+"user_id": 504569
+"add_time": "2017-04-19 11:18:10"
+"update_time": "2017-04-19 11:18:10"
+"visible_to": "7"
+"custom_view_id": null
+"conditions": {#219 ▼
+"glue": "and"
+"conditions": array:2 [▼
0 => {#230 ▼
+"glue": "and"
+"conditions": []
}
1 => {#223 ▼
+"glue": "or"
+"conditions": []
}
]
}
}
沒有錯誤,但是如您所見,條件為空。 我還嘗試了為Pipedrive API創建的PHP包裝器,並且得到了相同的結果。
管道驅動工程師在這里。 這是我測試過的一個例子。
<?php
$data = '
{
"name":"Custom filter less than 1000",
"type":"deals",
"visible_to":1,
"conditions":{
"glue": "and",
"conditions":[
{
"glue": "and",
"conditions": [
{
"object": "deal",
"field_id": "12452",
"operator": "<",
"value": 1000,
"extra_value": null
}
]
},
{
"glue": "or",
"conditions": []
}
]
}
}
';
$ch = curl_init("https://api.pipedrive.com/v1/filters?api_token=xxx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json;', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
echo $response;
注意
過濾API非常復雜,我們正在努力改進文檔。 希望這可以幫助
要進行交易,您應該使用GET
方法。 POST
用於添加交易。
將CURL
從POST
更改為GET
方法,它應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.