GraphQL Orders missing when filtered by discount code

JjjoooeeE
New Member
3 0 0

Hello,

We're currently using the shopify GraphQL API to search for orders using a given discount code from python like

code = 'code_to_search_for'
cursor = None
PAGE_SIZE = 100
has_next_page = True
while has_next_page:
    results = json.loads(shopify.GraphQL().execute(
                    'query orders($discount_code: String!, $cursor: String) { '
                    f'orders(first: {PAGE_SIZE}'
                    ', query: $discount_code, after: $cursor)'
                    ' { pageInfo{ hasNextPage } edges { cursor node { id name subtotalPriceSet '
                    '{ shopMoney { amount } } createdAt updatedAt discountCode } }}}',
                    {"discount_code": f'discount_code:{code}', "cursor": cursor},
                ))
    # pseudo code below, we handle missing json keys gracefully...
    cursor = results['data']['orders']['edges'][-1]['cursor']
    has_next_page = results['data']['orders']['pageInfo']['hasNextPage'] and cursor
    # .. do stuff with results['data']['orders']['edges'] nodes

In general this works, but found some codes where the initial query (cursor = None) returns no edges (although pageInfo.hasNextPage is True):

{'data': {'orders': {'pageInfo': {'hasNextPage': True}, 'edges': []}}, 'extensions': {'cost': {'requestedQueryCost': 202, 'actualQueryCost': 2, 'throttleStatus': {'maximumAvailable': 2000.0, 'currentlyAvailable': 1998, 'restoreRate': 100.0}}}}

If I grab a cursor from a different query that does return nodes (eg without a discount_code filter or even with a filter on a different code), the initial query does return edges, but is potentially missing nodes based on where that cursor came from (and mixing cursors from different queries seems very wrong!)?

Any ideas on what's happening here and how to fix?

Thanks!

0 Likes
mydevaccount
New Member
1 0 0

I'm also getting inconsistent responses from the python client vs the Shopify GraphQL app, specifically for Order data. Queries through the app appear to be correct but almost all data is missing via the Python client. I also tested via the url directly and got the same incorrect results.

0 Likes
SBD_
Shopify Staff
Shopify Staff
1065 143 186

@JjjoooeeE - Is the behaviour consistent when you hit the API directly? Or only when using the Python library? Are you able the grab a request ID from the response headers?

@mydevaccount - can you provide an example (including API version)?

0 Likes
JjjoooeeE
New Member
3 0 0

Yes, I can reproduce using a curl command line to the graphQL endpoint.

An example x-request-id: 4d674e5b-7296-4e10-86dc-f632700ec00d

0 Likes
SBD_
Shopify Staff
Shopify Staff
1065 143 186

Thanks I'm able to replicate. I've raised this internally. Keep you posted.

0 Likes
JjjoooeeE
New Member
3 0 0

Thanks, looking forward to your findings.

0 Likes