Covers all questions related to inventory management, order fulfillment, and shipping.
hi eveyone,
please respond
I have used this code to update inventory level
here is the code
import requests
# Your Shopify store URL and access token
shop_url = "XXXXXXXXXXX.myshopify.com"
access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# The GraphQL endpoint
graphql_url = f"https://{shop_url}/admin/api/2024-01/graphql.json"
# The GraphQL mutation for updating inventory quantity
mutation = """
mutation inventoryAdjustQuantity($input: InventoryAdjustQuantityInput!) {
inventoryAdjustQuantity(input: $input) {
inventoryLevel {
id
available
}
userErrors {
field
message
}
}
}
"""
# Variables for the mutation
variables = {
"input": {
"inventoryItemId": "37106128519331",
"locationId": "77564969224",
"availableDelta": +1 # Adjust by this amount, e.g., +5 to increase, -5 to decrease
}
}
# Headers including the access token and indicating JSON content
headers = {
"X-Shopify-Access-Token": access_token,
"Content-Type": "application/json"
}
# Performing the POST request with the mutation and variables
response = requests.post(graphql_url, json={"query": mutation, "variables": variables}, headers=headers)
# Checking the response
if response.status_code == 200:
# Parsing the JSON response
json_response = response.json()
print(json_response)
else:
print(f"Failed to update inventory: {response.status_code}")
but when i run the code the code it gives me the below error message
{'errors': [{'message': 'Variable $input of type InventoryAdjustQuantityInput! was provided invalid value for inventoryItemId (Field is not defined on InventoryAdjustQuantityInput), locationId (Field is not defined on InventoryAdjustQuantityInput), inventoryLevelId (Expected value to not be null)', 'locations': [{'line': 2, 'column': 34}], 'extensions': {'value': {'inventoryItemId': '37106128519331', 'locationId': '77564969224', 'availableDelta': 1}, 'problems': [{'path': ['inventoryItemId'], 'explanation': 'Field is not defined on InventoryAdjustQuantityInput'}, {'path': ['locationId'], 'explanation': 'Field is not defined on InventoryAdjustQuantityInput'}, {'path': ['inventoryLevelId'], 'explanation': 'Expected value to not be null'}]}}]}