I’m using following package : ‘osiset/Basic-Shopify-API’ and need bulk update products by location.
It’s only possible with GraphQL. This function should work :
inventoryBulkAdjustQuantityAtLocation Shopify documentation
$shop = 'example.myshopify.com';
$token = 'shppa_admin_api_token';
/ Create options for the API
$options = new Options();
$options->setVersion('2020-04');
// Create the client and session
$api = new BasicShopifyAPI($options);
$api->setSession(new Session($shop, $token));
$products[0]['inventoryItemId'] = '33125243617303';
$products[0]['availableDelta'] = 2000;
$result = $api->graph(
'mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: InventoryAdjustItemInput!,$locationId: ID!)
{inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $InventoryAdjustItemInput, locationId: $locationId) {userErrors {field message } inventoryLevels { id }}}',
['inventoryItemAdjustments' =>
$products
],
);
But I don’t understand how to use it. Could anyone help me ?
3
Answers
Now it works. It's a challenge to understand GraphQL queries if you never used them before.
Here are some more information :
https://www.shopify.com/partners/blog/multi-location_and_graphql
Not so good examples (hardcoded values, aliases – not real life examples) … graphql variables should be used and they should match mutation requirements (‘root’ parameters), in this case
locationId
andinventoryItemAdjustments
(array of objects).You can test this mutation in graphiql/playground using ‘query variables’ defined like this:
… so using php (associative arrays are encoded to json as objects – explicitely declared for readability) it should look more like this:
I would like to show another library that uses this and expand on the last example.
I am using a slightly different library for graphql:
https://github.com/Shopify/shopify-php-api/
Updating the inventory like it was posted here shows a [statusCode:GuzzleHttpPsr7Response:private] => 200
So it seems to work but does not reflect in updated inventory. 🙁
Checking at /admin/products/inventory?location_id=62241177806&query=F11_27781195
would not show the new inventory.
I am using the inventoryid correctly (not product or variantid).
Deleting a product works (and is a good test if the library is initialized well):