Add filter via API

Hi,
I want to add a new filter via API with the following conditions:

deal title starts with 123
OR
deal title starts with 234
OR
deal title starts with 345

Does anybody know how to create this request?
Thanks in advance!

Hi @Lilli

First, you need to get an ID of the deal’s title field.

After that, you can call POST /filters with the following body (but replace field_id with your field id).

{
   "name": "Title goes here",
   "type": "deals",
   "conditions": {
     "glue": "and",
     "conditions": [
        {
            "glue": "or",
            "conditions": [
                {
                    "object": "deal",
                    "field_id": 12451,
                    "operator": "LIKE '$%'",
                    "value": "123",
                    "extra_value": null
                },
                {
                    "object": "deal",
                    "field_id": 12451,
                    "operator": "LIKE '$%'",
                    "value": "234",
                    "extra_value": null
                },
                {
                    "object": "deal",
                    "field_id": 12451,
                    "operator": "LIKE '$%'",
                    "value": "345",
                    "extra_value": null
                }
            ]
        }
    ]
 }
}

Once it’s done, you should be able to find a filter in Pipedrive UI

Screenshot 2021-04-21 at 10.42.33

Hope it helps. More details here - Pipedrive API v1 Reference

1 Like

Hi @mykhailo

thanks for your help! I tried your solution but got the following error:

“success”:false,“error”:“operator: Invalid operator ‘LIKE’$%’’ for field ‘12492’”

Is the operator not available for the deal title field?

Best
Lilli

Hi @Lilli

Could you create a test filter from Pipedrive UI with similar conditions, for example

Call GET /filters from API to get the list of all filters and find an ID of a newly created filter. Use GET /filters/<id> to get its details, for example

This response body is similar to the one that was used upon creation, so you could extract filed_id, operators, and format for the actual filter you need.

1 Like

@mykhailo Thanks! Apparently the blank space was anything different than a blank space. Now it works :slight_smile:!

1 Like