GraphQL API internal error for productDelete (RequestID included)

manhnq94
Excursionist
30 1 5

Hi Shopify Dev team,

I ran the following query and the GraphQL server responded with an internal error message. Please help me check why this is happened.

Request ID: 586a70fb-334f-4b27-b462-71060c439756

My code:

def callShopifyGraphQL(apiKey, apiPassword, shopAdminURL, graphQLString, variables=None):
    shop_url = f'https://{apiKey}:{apiPassword}@{shopAdminURL}/admin/api/2020-07'

    headers = {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": apiPassword
    }
    
    if variables is None:
        response = requests.post(shop_url+'/graphql.json', json={'query': graphQLString})
    else:
        response = requests.post(shop_url+'/graphql.json', json={'query': graphQLString, 'variables': variables}, headers=headers)
    
    if response.status_code == 400:
        raise ValueError('GraphQL error:' + response.text)
        
    answer = json.loads(response.text)
    throttleStatus = None
    if 'errors' in answer:
        try:
            throttleStatus = answer['errors'][0]['extensions']['code']
        except:
            pass
        if throttleStatus != 'THROTTLED':
            raise ValueError('GraphQL error:' + repr(answer['errors']))

    qlRequired = answer['extensions']['cost']['requestedQueryCost']
    qlLimit = answer['extensions']['cost']['throttleStatus']['maximumAvailable']
    qlAvail = answer['extensions']['cost']['throttleStatus']['currentlyAvailable']
    
    print('GraphQL throttling status: ' + str(qlAvail) + '/' + str(int(qlLimit)))
    
    while throttleStatus == 'THROTTLED':
        print('Waiting (GraphQL throttling)... ' + str(qlAvail) + '/' + str(int(qlLimit)) + ' used, requested ' + str(qlRequired))
        time.sleep(1)
        
        if variables is None:
            response = requests.post(shop_url+'/graphql.json', json={'query': graphQLString})
        else:
            response = requests.post(shop_url+'/graphql.json', json={'query': graphQLString, 'variables': variables}, headers=headers)
            
        answer = json.loads(response.text)
        try: 
            throttleStatus = answer['errors'][0]['extensions']['code']
        except:
            throttleStatus = None
            pass
    return answer['data']

graphQLDeleteProductQuery = """
	mutation productDelete($input: ProductDeleteInput!) {
		productDelete(input: $input) {
			deletedProductId
			userErrors {
				field
				message
			}
		}
	}
"""

variablesDeleteProduct = {
	"input": {
		"id": graphqlProductID
	}
}

deleteProductResult = callShopifyGraphQL(storeAPIKey, storeAPIPassword, storeAdminDomain, graphQLDeleteProductQuery, variablesDeleteProduct)

 

Response: 

GraphQL error:[{'message': 'Internal error. Looks like something went wrong on our end.\nRequest ID: 586a70fb-334f-4b27-b462-71060c439756 (include this in support requests).', 'extensions': {'code': 'INTERNAL_SERVER_ERROR', 'requestId': '586a70fb-334f-4b27-b462-71060c439756'}}]

Reply 1 (1)
syf_
Shopify Staff
Shopify Staff
95 21 23

Hi @manhnq94,

From what I can see from the logs that request timed out, and retrying the query should have worked. From the logs, the product you were trying to delete was successfully deleted a couple of seconds after you made the request whose request id you provided. 

Timeouts usually result in a 500 response (INTERNAL_SERVER_ERROR), and Shopify's recommendation is to retry the request again after 1 second - this almost always succeeds.

Would I be right in noting this was a timeout, and retrying the request worked?

Let me know if you have any questions.

Best,

Seth

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