API filtering does not work

Any critical bugs will be fixed within 24-48 hours.
Post Reply
thielem
Posts: 22
Joined: 12 Mar 2023, 22:30
Name: Moritz Thiele
Location: Germany, Berlin

API filtering does not work

Post by thielem »

I am attempting to use the API with Python. Unfortunately, the filter function does not work. I thought this was an issue with lacking JSON support, but it still persists in version 3.5

Code: Select all

def get_user_info(user_id:int):
    
    field_keys = {
        "8": "user",
        "271": "f1",
        "867": "f2",
        "956": "f3",
        "282": "f4",
        "333": "f5",
        "334": "f6",
        "1039": "f7",
        "574": "f8",
        "1057": "f9",
        "1058": "f10"
    }
    
    params = {
        'action': 'select',
        'entity_id': 1,
        'select_fields': ", ".join(field_keys.keys()),
        'filters': {
            'id': user_id
        }
    }
    
    params = {**API_CREDENTIALS, **params}
    r = requests.post(API_ENDPOINT, data=params, headers=cf_credentials)
    
    res_json = json.loads(r.text)
    if res_json["status"]=="success":
        return res_json['data'][0]
    return None
    

This returns all users in res_json["data"] and the filter has no effect.
User avatar
support
Site Admin
Posts: 6215
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: API filtering does not work

Post by support »

Checked in PHP and filters by ID works ok.
User avatar
support
Site Admin
Posts: 6215
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: API filtering does not work

Post by support »

See my request

Code: Select all

key=bWz3m64fePZSQMjfV2IzzlFPgGXJkRlrWZLb91AK&username=admin&password=admin&action=select&entity_id=21&select_fields=158%2C157%2C255%2C232%2C156%2C+258%2C+158%2C344%2C162&limit=0&filters%5Bid%5D=8
User avatar
support
Site Admin
Posts: 6215
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: API filtering does not work

Post by support »

Also in 3.5 you can send json

Code: Select all

{
    "key": "bWz3m64fePZSQMjfV2IzzlFPgGXJkRlrWZLb91AK",
    "username": "admin",
    "password": "admin",
    "action": "select",
    "entity_id": 21,
    "select_fields": "158,157,255,232,156, 258, 158,344,162",
    "limit": 0,
    "filters": {
        "id": 8
    }
}
thielem
Posts: 22
Joined: 12 Mar 2023, 22:30
Name: Moritz Thiele
Location: Germany, Berlin

Re: API filtering does not work

Post by thielem »

Replacing
requests.post(API_ENDPOINT, data=params, headers=cf_credentials)
with
requests.post(API_ENDPOINT, json=params, headers=cf_credentials)

fixed it. Thanks for the JSON update!
Post Reply