Hi AdvancedModel,
From a quick look, the code you have posts seems okay. Here are a couple of things you can check:
-
Permissions: Make sure the access token you are using has the right permissions to update the inventory.
-
Data: Ensure the data you are sending in the
invItemAdjustmentsvariable is correctly formatted and contains valid inventory item IDs and location IDs. -
Error Handling: The
response.Errorsonly contains GraphQL syntax errors. Shopify also returns user errors in theuserErrorsfield in the response body which describes the application-specific errors. You are querying it, but not checking it. These are errors like missing permissions or invalid data. -
Location ID: You’ve mentioned
<correct>in the locationId. Ensure you’re replacing this with a valid location ID.
Here’s how you can modify your code to handle userErrors:
if (response.Data?.InventoryBulkAdjustQuantitiesAtLocationMutation?.UserErrors?.Count > 0)
{
// Handle user errors for this batch
foreach (var error in response.Data.InventoryBulkAdjustQuantitiesAtLocationMutation.UserErrors)
{
_logger.LogError("User error from GraphQL API in field {0}: {1}", error.Field, error.Message);
}
}
else
{
InventoryBulkAdjustResponse inventoryLevels = response.Data;
// Rest of your code
}
Note: The InventoryBulkAdjustQuantitiesAtLocationMutation should match the name you provide in your deserialized response class. If you’re still encountering issues, try running the same mutation query manually in the Shopify GraphiQL app to see if you get any additional errors there.
Hope this helps,