Untitled
unknown
plain_text
a year ago
2.2 kB
9
Indexable
def _update_inventory(self, inventory):
# set up the inventorySetOnHandQuantities mutation for use with v. 2024-04
graphql_query = {
"query": """
mutation inventorySetOnHandQuantities($input: InventorySetOnHandQuantitiesInput!) {
inventorySetOnHandQuantities(input: $input) {
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
userErrors {
field
message
}
}
}
""",
"variables": {
"input": {
"reason": "correction",
"referenceDocumentUri": "logistics://some.warehouse/take/2023-01-23T13:14:15Z",
"setQuantities": [
{
"inventoryItemId": f"gid://shopify/InventoryItem/{inventory['inventory_item_id']}",
"locationId": f"gid://shopify/Location/{inventory['location_id']}",
"quantity": inventory["available"]
}
]
}
}
}
# send request to GraphQL endpoint
response = self._send_post_request("graphql.json", graphql_query)
# check for success
if (response and "data" in response and
response["data"]["inventorySetOnHandQuantities"].get("inventoryAdjustmentGroup")):
self.db_conn.update_inventory_timestamp(shopify_inventory_item_id=inventory["inventory_item_id"])
print(f"Inventory update: ID {inventory['inventory_item_id']} set to "
f"{inventory['available']} successfully", color=GREEN)
else:
print(f"Error: Failed to update inventory ID {inventory['inventory_item_id']}: {response}", error=True)Editor is loading...
Leave a Comment