过滤器端点的Pipedrive API PUT和POST请求不起作用 [英] Pipedrive API PUT and POST requests for Filters endpoint not working
问题描述
我正在尝试从Pipedrive API中提取特定日期范围内的Deals.我可以通过使用所需日期范围的API编辑(或创建/删除)过滤器,然后在随后的请求中传递该过滤器来拉动所有交易来实现这一目的.
I'm trying to pull Deals from the Pipedrive API for a specific date range. I'm accomplishing this by editing (or creating/deleting) a filter via the API with the date range I want, and then passing in that filter in a subsequent request to pull all deals.
交易"端点工作正常.我的问题是,API似乎不喜欢我为过滤器"终结点传递的"conditions"参数,但仅当我使用cURL(在我自己的代码中)或Postman时才是如此.如果我在API文档中测试了编辑过滤器"或创建过滤器"端点,则当我将我的代码中的JSON对象复制并粘贴到"conditions"参数中时,它们均能按预期工作.但是,如果我使用cURL或Postman,则PUT端点仅返回我正在编辑的过滤器而不对其进行编辑,而POST端点将创建一个空条件的新过滤器.
The "deals" endpoint works perfectly. My problem is that the API doesn't seem to like the "conditions" parameter that I'm passing in for the "filters" endpoint--but only if I'm using cURL (in my own code) or Postman. If I test either the "edit filter" or "create filter" endpoints in the API docs, both of them work exactly as intended when I copy and paste the JSON object from my code into the "conditions" parameter. However, if I use cURL or Postman, the PUT endpoint simply returns the filter I'm editing without editing it, and the POST endpoint creates a new filter with empty conditions.
这是我用于POST端点的PHP代码:
Here's the PHP code I'm using for the POST endpoint:
$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);
这是创建过滤器"端点的条件"参数的说明:
And this is the description of the "conditions" parameter for the "create filter" endpoint:
将条件过滤为JSON对象.它要求的最小结构如下:
"Filter conditions as a JSON object. It requires a minimum structure as follows:
{"glue":"and","conditions":[{"glue":"and","conditions": [CONDITION_OBJECTS]},{"glue":"or","conditions":[CONDITION_OBJECTS]}]}
用以下结构的JSON对象替换CONDITION_OBJECTS:
Replace CONDITION_OBJECTS with JSON objects of the following structure:
{"object":"","field_id":"", "operator":"","value":"", "extra_value":""} or leave the array empty.
根据对象类型,您应该使用另一个API端点来获取field_id.您可以选择五种对象:
Depending on the object type you should use another API endpoint to get field_id. There are five types of objects you can choose from:
"person", "deal", "organization", "product", "activity"
,您可以使用以下类型的运算符,具体取决于您拥有的字段类型:
and you can use these types of operators depending on what type of a field you have:
"IS NOT NULL", "IS NULL", "<=", ">=", "<", ">", "!=", "=", "LIKE '%$%'", "NOT LIKE '%$%'", "LIKE '$%'", "NOT LIKE '$%'", "LIKE '%$'", "NOT LIKE '%$'".
要更好地了解过滤器的工作原理,请尝试直接从Pipedrive应用程序中创建过滤器."
To get a better understanding of how filters work try creating them directly from the Pipedrive application."
POST端点的"conditions"参数相同.同样,当我将该大JSON对象粘贴到API docs测试中时,两个端点都可以正常工作-但不适用于我自己的代码.任何帮助将不胜感激.
The POST endpoint's "conditions" parameter is the same. Again, when I paste that big JSON object into the API docs test, both endpoints works perfectly--but not in my own code. Any help would be appreciated.
这是我从cURL获得的创建过滤器"端点的响应:
this is the response I get from cURL for the "create filter" endpoint:
{#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包装器,并且得到了相同的结果.
No errors, but as you can see, the conditions are empty. I also just tried the PHP wrapper that was created for the Pipedrive API and am getting the same result.
推荐答案
Pipedrive工程师在此处.这是我测试过的一个例子.
Pipedrive engineer here. Here is an example I tested..
<?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;
注意
- 整个json是原始发布的
- 我添加了Content-Type标头
- 我在参数中添加了visible_to
过滤API非常复杂,我们正在努力改进文档.希望这会有所帮助
Filtering API is quite complex and we are working on improving documentation. Hope this helps
这篇关于过滤器端点的Pipedrive API PUT和POST请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!