labd / commercetools-python-sdk

Commercetools Python SDK
https://commercetools-python-sdk.readthedocs.io/en/latest/
MIT License
17 stars 16 forks source link

querying /orders/search endpoint through always an error #143

Open zaidoun-flaconi opened 1 year ago

zaidoun-flaconi commented 1 year ago

I'm trying to query https://docs.commercetools.com/api/projects/order-search#search-orders endpoint by calling:

range_query = {
    "query" : {
    "and": [
        {
            "range": {
                "field": "createdAt",
                "gte": "2023-05-31T23:00:00.000Z"
            }
        },
        {
            "exact": {
                "field": "store.key",
                "value": "at"
            }
        }
    ]
},
    "sort" : None,
    "limit" : 10,
    "offset": 10
}

orderSearchRequest = OrderSearchRequest("query"=range_query) ctClient = client.with_project_key("prod").orders().search().post(body=orderSearchRequest}))

The root cause is the deserialize of orderSearchRequest in the post request body results in a empty dict which results in '400' error code CT response with following message b'{"code":400,"errors":["Invalid JSON at \'.query\': Exactly one [fullText], [exact], [prefix], [wildcard], [range] or [exists] expression needed."]}'

could you please assists what is missing here? thanks