我試圖從Pipedrive API爲特定日期範圍提交交易。我正在通過編輯(或創建/刪除)一個過濾器來實現這一點,並通過具有我想要的日期範圍的API,然後在隨後的請求中傳入該過濾器來提取所有交易。Pipedrive API PUT和POST請求過濾器端點不工作
「交易」端點完美運作。我的問題是,API似乎不喜歡我爲「過濾器」端點傳入的「條件」參數 - 但只有當我使用cURL(在我自己的代碼中)或Postman時。如果我在API文檔中測試「編輯過濾器」或「創建過濾器」端點,那麼當我從代碼中將JSON對象複製並粘貼到「條件」參數中時,它們都按預期工作。但是,如果我使用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]}]}
具有以下結構的JSON對象替換CONDITION_OBJECTS:
{"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端點的」conditions「參數是相同的。再一次,當我將這個大的JSON對象粘貼到API文檔測試中時,兩個端點完美地工作 - 在我自己的代碼中,任何幫助都可以ciated。
編輯:這是我從捲曲獲得了「創建過濾器」端點響應:
{#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包裝器,並獲得了相同的結果。
打印Curl拋出的錯誤。 http://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php – Samir
@薩米爾剛剛編輯的OP與我得到的響應。沒有錯誤被拋出。 –