Possible bug: orders-api return limit - 1 records when sorted by CREATED_AT = ASC

I called /v2/orders/search and specified the sort_field on CREATED_AT, with limit, like so:

{
    "location_ids": [ "ABC" ],
    "limit": 2,
    "query": {
        "sort": {
            "sort_field": "CREATED_AT",
            "sort_order": "ASC"
        }        
    }
}

If the sort_order is ASC, the API returns only 1 order in the orders array. If the sort order is DESC, the API returns 2 orders as expected. The cursor attribute is returned in both cases. There are more than 30 orders in my test account. It is even more strange if limit is 1. I’d get only the cursor attribute returned with no orders attribute when sort_order = ASC.

Overall, it seems like orders API would return limit - 1 records if sort_order = ASC. I have not tested other sort_field values, though.

I do not believe this is the intended behavior. Can someone from Square please confirm? Thanks.

:wave: Looks like it’s only returning COMPLETED orders instead of all the orders. I’ve reached out to the team about this. :slightly_smiling_face:

Thanks for looking into this. I have more than one COMPLETED orders in my account. Regardless, changing from DESC to ASC should not result in # of records being returned – the sort order should just flip.

According to the team the limit is the maximum number of results to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page and you’ll need to paginate through the results. :slightly_smiling_face: