Tuesday 21 November 2023

Python Filtering OData Entity by Parent - Requests Library

I have an OData API I'm trying to query using the Python Requests library. I'm trying to filter a table based on the parent table for an incremental data pull. The children tables don't use a last_update_date, but I can get this date from the parent as the parent's last_updated_date changes even if the change is in a child table. Note that in my example, employees is the parent entity of employee_texts.

My code looks like the below:

data = requests.get(
    endpoint_url + "employee_texts"
    , auth=(api_username, api_password)
    , params={
        "$filter": "employees/LastModifiedDate gt 2023-11-15T00:00:00.00Z",
        "$format": "json"
    }
    , verify=True
)

If I run this, I get the below error:

{'error': {'code': '',
'message': 'Value cannot be null.\r\nParameter name: type'}}

Please note that this code works as expected:

data = requests.get(
    endpoint_url + "employees"
    , auth=(api_username, api_password)
    , params={
        "$filter": "LastModifiedDate gt 2023-11-15T00:00:00.00Z",
        "$format": "json"
    }
    , verify=True
)


from Python Filtering OData Entity by Parent - Requests Library

No comments:

Post a Comment