Change in stock items on test account

spink90spink90 Member Posts: 6

Hello


I am trying to change the stock quantity of selected items via a php action(I need to modify the stock quantity according to order (subtract the correct amount in accordance with the order)), unfortunately, I couldn't find the right materials in the documentation(I may have missed them).


After authentication at https://cloud.lightspeedapp.com/oauth/authorize.php?response_type=code&client_id=...&scope=employee:all


Then after receiving code `/gettokenls?Code=b70eaf72004e2001fe7452349584e6d4b76b9176`, and downloaded token.


I have added a sample item manually to `Items & Inventory` (https://us.lightspeedapp.com/?name=item.views.item&form_name=view&id=1&tab=details)


I checked the documentation https://developers.lightspeedhq.com/retail/endpoints/Item/ and https://developers.lightspeedhq.com/retail/endpoints/Order/


Unfortunately, I did not find any examples of changes in the storage quantity(how should I deduct quantities item now?), given in php


Can I ask someone from the team to guide me to the right solution for my problem, alternatively, please direct me to an example.

8 comments

  • gregaricangregarican Member Posts: 336 
    edited November 12

    This is interesting. Here below is my test API request URI and JSON body.


    "https://api.merchantos.com/API/Account/{AccountId}/Item/55.json"


     "Note": { 

      "note": "This is a newly-updated note." 

     },

     "ItemShops": {

      "ItemShop": {

       "itemShopID": 164,

       "shopID": 1,

       "qoh": 1

      }

     }

    }


    All I'm doing is updating the note for ItemId 55 and changing the on-hand quantity to 1 for the first shop in the account.


    When I look in the web client, I see the note was updated, and the site quantity is updated for the first shop. But the sum quantity available isn't updated. Screen shot below.


    Assuming that I'm missing something in the JSON body, although I can't see where. Usually when you pull a record using the GET request, you can mimic the JSON body in the PUT request to update a record and get consistent results.

  • gregaricangregarican Member Posts: 336 

    @Adrian Samuel do you have any input as to this?

  • gregaricangregarican Member Posts: 336 
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 573 moderator

    Hey @spink90,

    Greg's comment should suffice in providing an answer.

    As he's shown , you'll need to specify the ItemShopID in the payload and then set the qoh field. You cannot deduct a number, you can only set a number.

    So if for example you want to change qoh from 10 to 5, you'll have to do the math in your code and simply send in the payload, the "5" you want to set.

    @gregarican, the reason your sum isn't updated because "In Stock" field is specified per store and not for all stores. You are logged in SawMill boutique whereas your stock is in MXC. If you change stores, you'll see the "In Stock" integer show correctly show


    Hope this helps!

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • gregaricangregarican Member Posts: 336 

    Ahh I see. That makes sense now. Thanks @Adrian Samuel for the reminder. I thought the In Stock field was just a sum total across all shops. I'll file that one away for next time I have to work with this endpoint!

  • spink90spink90 Member Posts: 6
    edited November 14

    Hello

    @Adrian Samuel

    Thank you for your earlier reply.

    But what happens if:

    1) I have two applications

    2) Both applications will want to deduct 1 at the same time

    Does this mean that yours software will report incorrect inventory?


    @gregarican

    Thank you too for the answer

  • spink90spink90 Member Posts: 6

    From GET

    $putURL = "https://api.lightspeedapp.com/API/Account/".$account_id."/Item/1.json?load_relations=all";
    

    I get this answer

    {"response":{"@attributes":{"count":"1"},"Item":{"itemID":"1","systemSku":"210000000001","defaultCost":"1","avgCost":"1","discountable":"false","tax":"true","archived":"false","itemType":"serialized","serialized":"true","description":"Item test 1","modelYear":"0","upc":"12345678910","ean":"12345678910","customSku":"1234","manufacturerSku":"1234","createTime":"2019-11-12T09:55:41+00:00","timeStamp":"2019-11-14T14:54:59+00:00","publishToEcom":"false","categoryID":"0","taxClassID":"1","departmentID":"0","itemMatrixID":"0","manufacturerID":"0","seasonID":"0","defaultVendorID":"0","TaxClass":{"taxClassID":"1","name":"Item","timeStamp":"2019-11-12T09:09:22+00:00"},"Note":{"note":"","isPublic":"false","timeStamp":"2019-11-14T14:54:58+00:00"},"ItemShops":{"ItemShop":[{"itemShopID":"2","qoh":"166","sellable":"166","backorder":"0","componentQoh":"0","componentBackorder":"0","reorderPoint":"0","reorderLevel":"0","timeStamp":"2019-11-14T14:54:59+00:00","itemID":"1","shopID":"1","m":{"layaways":"0","specialorders":"0","workorders":"0"}},{"itemShopID":"1","qoh":"166","sellable":"166","backorder":"0","componentQoh":"0","componentBackorder":"0","reorderPoint":"0","reorderLevel":"0","timeStamp":"2019-11-14T14:54:59+00:00","itemID":"1","shopID":"0","m":{"layaways":"0","specialorders":"0","workorders":"0"}}]},"Prices":{"ItemPrice":[{"amount":"1","useTypeID":"1","useType":"Default"},{"amount":"1","useTypeID":"2","useType":"MSRP"}]},"Tags":{"@attributes":{"count":"1"},"tag":"testitem1"}}}}
    

    But when I try to change qoh (PUT)

    $postFields = '{ "ItemShops": { "ItemShop": { "itemShopID": 1, "qoh": 3 }}}';
    

    I get this answer

    {"response":{"httpCode":"400","httpMessage":"Bad Request","message":"Item not Update. The ItemShop record with shopID 0 cannot have its qoh field changed.","errorClass":"Exception"}}
    

    Thank you in advance for help

Sign In or Register to comment.