Can't Access Images in Node

Hi,
I'm struggling to access images in Node. Would anyone mind telling me what is wrong with my path please?
itemID: item.itemID, customSku: item.customSku, qoh: parseInt(item.ItemShops.ItemShop[0].sellable), price: item.Prices.ItemPrice[0].amount, images: item.Images.Image.filename
9 comments
Aren't images an array? And also the images are accessed via load_relations in the API request I believe.
Here attached is a sample API request/response pair that pulls images. Maybe this helps?
Hey @darryl_ss,
You need to need to call the Item Image endpoint to get the image url for a given item: https://developers.lightspeedhq.com/retail/endpoints/Item-Image/
Adrian Samuel
Software Developer
Lightspeed HQ
Hi @Adrian Samuel & @gregarican ,
I am accessing using relations. I'm not seeing an array for Images?
If I recall that was a gotcha. Most standard API responses will always define an array as an array. Even if it contains a single element. Like "Images": [ { "Image": {"blahblahblah"} } ] In the case of the Retail API, if the array has a single element then the brackets are dropped. As in your example code, "Images": { "Image": {"blahblahblah"} }
Ok, thanks @gregarican. So it should be - item.Images[0].Image.filename?
I don't use Node, so I'm not 100% sure. But I do know for my C# project I had to perform a bunch of checks against these properties, to check if the values were an array or just a singleton based on the JSON response. I finally created a generic method that would handle these. Too bad that Lightspeed doesn't adhere to standardized ways of handling this.
Thanks for the help @gregarican, I'm new to this game, but my experience of Epos api's has been that it's never the easy way ;)
Here is how I handle this using JSON.NET in the C# world. You could translate something similar to your Java/JavaScript world I'm sure :)
And another caveat is some fields that have NULL values aren't even returned in the API response at times. If your handlers are looking for consistent data set properties appearing in each API response then that can break things. As discussed here --> https://community.lightspeedhq.com/en/discussion/1936/inventory-transfer-json-response-missing-fields.
Funnily enough, the beginner that I am. This issue was related to null values and I needed to filter them out, damn it. Ha! I will learn sooner or later ;)
Thanks for the info it is much appreciated!