GraphQL Orders missing when filtered by discount code

New Member
1 0 0


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
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?


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.