FROM CACHE - en_header

GraphQL Orders missing when filtered by discount code

JjjoooeeE
Shopify Partner
5 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!

Replies 8 (8)
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.

SBD_
Shopify Staff
Shopify Staff
1098 146 220

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

Scott | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

JjjoooeeE
Shopify Partner
5 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

SBD_
Shopify Staff
Shopify Staff
1098 146 220

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

Scott | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

JjjoooeeE
Shopify Partner
5 0 0

Thanks, looking forward to your findings.

JjjoooeeE
Shopify Partner
5 0 0

@SBD_any updates on this?

SBD_
Shopify Staff
Shopify Staff
1098 146 220

Hey @JjjoooeeE 

I just chased this up internally and in the process I'm unable to replicate. Can you please give it another shot and let me know if you hit the same error (and if so provide the request ID)?

Scott | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

JjjoooeeE
Shopify Partner
5 0 0

x-request-id: d4feb814-cbfb-4b14-9e0d-3ce2319ebcb1 still appears to have the same problem