Inventory Transfer JSON Response Missing Fields?

gregaricangregarican Posts: 307Member 

I have an automated routine running that's been in place for about a year now. It ports in everything from inventory to customers to sales to refunds to vendors to transfers to employees each day. The API transfer response from last night failed to port in successfully. Since I am looking for the key data fields in the response and this one had a missing element.

I'll paste the API response below. Note that the sentOn field isn't provided. Even if it's a null value, shouldn't this element be passed back? Looking at the API documentation (https://developers.lightspeedhq.com/retail/endpoints/Inventory-Transfer/) it still appears in there. Seems to be many inconsistencies and workarounds in what should be standard API without gotchas. Another example is an element that can be an array. When there are multiple items in the element then it's passed back as an array. When there is a single item, then it's not passed back as an array with a single item. It's passed back as a singleton that isn't an array type. But I digress :) Anyone have feedback about this missing element?


{"Transfer": {

 "transferID": "1930",

 "note": "",

 "archived": "false",

 "timeStamp": "2019-05-09T13:04:15-04:00",

 "createTime": "2019-05-09T13:04:06-04:00",

 "status": "open",

 "needBy": "2019-05-09T17:00:00-04:00",

 "sendingShopID": "3",

 "sentByEmployeeID": "0",

 "receivingShopID": "1",

 "createdByEmployeeID": "33"

}}

12 comments

  • gregaricangregarican Posts: 307Member 

    Usually when an API response is unexpected somehow I look in the web client to see what it looks like. In this case the Transfer 1930 appears to be invalid. In that the sending site didn't even have the item on-hand. The transaction was allowed to be saved, and I'm assuming that's why the sentOn was N/A. Since there wasn't a quantity to send. Screen shots attached.


    Regardless, if the transaction was allowed to be saved in the web client, shouldn't the sentOn be passed back in the API response as null?

  • gregaricangregarican Posts: 307Member 

    Just pinging this for any feedback from the Lightspeed Retail API team...

  • gregaricangregarican Posts: 307Member 
  • gregaricangregarican Posts: 307Member 
  • Alex LugoAlex Lugo Posts: 138Administrator, Lightspeed Staff moderator

    Hi @gregarican,

    Let me check this, I'll update you as soon as possible.

    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • gregaricangregarican Posts: 307Member 

    So any feedback? Since apparently the Community board is the primary place to seek API support, I am looking forward to the good word :)

  • gregaricangregarican Posts: 307Member 

    Pinging this again.

  • gregaricangregarican Posts: 307Member 

    Not saying this is necessarily the case, although sometimes I feel like it :(


  • Alex LugoAlex Lugo Posts: 138Administrator, Lightspeed Staff moderator

    Hello @gregarican,

    I apologize for the really long delay from my part. If the Transfer hasn't been sent in the UI, is by design that the field sentOn will not be present in the response. Once the transfer is sent to its destination the field sentOn will be included in the response.

    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • gregaricangregarican Posts: 307Member 
    edited May 28

    Thanks for getting back to me. While I can understand a null value being the case when the record was created on the web client front-end, an API should consistently pass back all fields. Regardless of their values being provided or not. Hence the null.

    A basic hypothetical example would be a customer endpoint. Say there's a first name, middle initial, and last name field. While the majority of records might not have a middle initial value, the API consumer would still be looking for all three fields in the API response. Even if null. Like this dummy response below:

    { customer:

    { first_name: "Joe",

    middle_initial: null,

    last_name: "Schmoe"}

    }

    Otherwise any custom API code by a consumer has to account for previously-unknown gotchas, since the JSON structure being returned could differ due to the inconsistency.

  • Alex LugoAlex Lugo Posts: 138Administrator, Lightspeed Staff moderator

    Hi @gregarican,

    You have a valid point, that why I brought this to our Product Manager attention, I can't warranty that this behaviour will change, but they're aware of this, if this gets implemented I will let you know.

    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • maurisourcemaurisource Posts: 26Partner partner

    Hi,

    +1 @gregarican on this. It would be nice that the API returns the field even when it's empty. Instead, it hides it from the Json response. This sometimes break my code now and then with this error in PHP:

    ErrorException : Undefined index:

    So as a workaround, I have to wrap isset() statement in PHP around every possible field that can be unset in the response! This is undeniably time-consuming.. 😩

Sign In or Register to comment.