x

Question on Inventory Change API

I am integrating the Inventory Change API to integrate the Squareup to the ecommerce website. 

I am able to use this code without problems. 

$adjustment = new \Square\Models\InventoryAdjustment();
$adjustment->setFromState('IN_STOCK');
$adjustment->setToState('SOLD');
$adjustment->setLocationId('XXXXXXXXXX');
$adjustment->setCatalogObjectId('XXXXXXXXXXX');
$adjustment->setQuantity('4');
$adjustment->setOccurredAt('2020-12-11T12:16:09+00:00');

$inventory_change = new \Square\Models\InventoryChange();
$inventory_change->setType('ADJUSTMENT');
$inventory_change->setAdjustment($adjustment);

$changes = [$inventory_change];
$body = new \Square\Models\BatchChangeInventoryRequest();
$body->setIdempotencyKey('some-key');
$body->setChanges($changes);
$body->setIgnoreUnchangedCounts(true);

$api_response = $client->getInventoryApi()->batchChangeInventory($body);

if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}

I could call this API when a product is been sold in the eCommerce Website so that I have to update the count in the Square POS - here, 4 quantity of the Product was sold so, I have given 4 as Quantity. 

How should I use this API if I want to increase the quantity of a product from my ecommerce website. Like the quantity is now 10 in the Website and Square POS. Now, I received 5 more items from the vendor - I would edit the ecommerce admin Product catalog and make it 15. So,  quantity is increased 5 in numbers. 

In order to make the quantity of the Product from 10 to 15 ( or just add 5 ) how should I use this API ? I tried changing the from state and to state from various states and did not work for me. Could someone please guide me on this ? 

456 Views
Message 1 of 2
Report
1 REPLY 1
Alumni

We recommend taking a look at this helpful documentation about the supported state transitions, @jishcem.

If you're just wanting to add stock, you will most likely want to use from_state == NONE and to_state == IN_STOCK to add inventory. If you still need a bit of help, I put together a post including links to resources for developers here. I hope this helps! 

Valentina
Community Moderator, Square
Sign in and click Mark as Best Answer if my reply answers your question.
415 Views
Message 2 of 2
Report