Assigning Images to Items

gregaricangregarican Posts: 82Member ✭
Awhile back we ported in ~4K products into Lightspeed Retail. The majority of these items had multiple images associated with them. Since the Lightspeed Retail API only allowed a single image POST at a time, the process was rather lengthy. But everything came in fine. Even the ordering of the images in the web client, in terms of which image is primary and whatnot.

But when I look at the image arrays for these API-created items now, it appears that the Ordering element for each item's image array is always just set to 0. I would've expected each POST'ed image to the item would auto-increment the Ordering value on the back-end. So that the first image loaded would go into Slot 0, the second image into Slot 1, and so on.

I'll paste a bit of the JSON below so you can see what I'm talking about. This was a minor gotcha, since the API documentation didn't provide a detailed rundown about item images. Where it's an issue is when we pull the item image data, we will need to programmatically evaluate the TimeStamp and the ImageID in order to determine what the image ordering is.

I would suggest either specifying in the API documentation that this Ordering element should be explicitly provided by the API caller, or perhaps enhancing the back-end handling of the API call so that the images auto-increment their Ordering element values if not explicitly supplied. 

Make sense?

"Images": {
            "Image": [
                {
                    "imageID": "4619",
                    "description": "",
                    "filename": "IMG_5380.jpg",
                    "ordering": "0",
                    "publicID": "xbsj9awmdk6ovhtnseqk",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "36017",
                    "createTime": "2018-06-04T05:03:14+00:00",
                    "timeStamp": "2018-06-04T05:03:14+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                },
                {
                    "imageID": "4620",
                    "description": "",
                    "filename": "IMG_5387.jpg",
                    "ordering": "0",
                    "publicID": "m48kyy9bv9m95ms8xlpd",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "43983",
                    "createTime": "2018-06-04T05:03:25+00:00",
                    "timeStamp": "2018-06-04T05:03:25+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                },
                {
                    "imageID": "4621",
                    "description": "",
                    "filename": "IMG_5385.jpg",
                    "ordering": "0",
                    "publicID": "dkcdm0qmknnv2wqwfvtp",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "64564",
                    "createTime": "2018-06-04T05:03:36+00:00",
                    "timeStamp": "2018-06-04T05:03:36+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                },
                {
                    "imageID": "4622",
                    "description": "",
                    "filename": "IMG_5382.jpg",
                    "ordering": "0",
                    "publicID": "pco4ro5uqrnpg6tlo1p7",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "26070",
                    "createTime": "2018-06-04T05:03:47+00:00",
                    "timeStamp": "2018-06-04T05:03:47+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                },
                {
                    "imageID": "4623",
                    "description": "",
                    "filename": "IMG_5384.jpg",
                    "ordering": "0",
                    "publicID": "tpnamr1k2bagu898dttg",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "59695",
                    "createTime": "2018-06-04T05:03:58+00:00",
                    "timeStamp": "2018-06-04T05:03:58+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                },
                {
                    "imageID": "4624",
                    "description": "",
                    "filename": "IMG_5381.jpg",
                    "ordering": "0",
                    "publicID": "msfgoq7ju9ocvvba7zha",
                    "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                    "size": "29868",
                    "createTime": "2018-06-04T05:04:10+00:00",
                    "timeStamp": "2018-06-04T05:04:10+00:00",
                    "itemID": "2545",
                    "itemMatrixID": "0"
                }
            ]
        }

4 comments

  • gregaricangregarican Posts: 82Member ✭
    edited September 19
    What's odd is I look at a different item that was also added via the API. This item appears to have the image array defined correctly. In terms of the Ordering element reflecting the sequential values. I'll paste that below. Both of these items show "API Added" in the web client's Item History tab.

    The only difference I see is that only the primary image was created when the item was ported in via the API. The other images were added later manually in the web client. Perhaps that action caused the Ordering elements to automatically align. Shame that the initial API push doesn't do this!


    "Images": {
                "Image": [
                    {
                        "imageID": "5612",
                        "description": "",
                        "filename": "257880-7.jpg",
                        "ordering": "0",
                        "publicID": "j00phf4exeycygeshood",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "83007",
                        "createTime": "2018-06-04T09:20:34+00:00",
                        "timeStamp": "2018-06-04T09:20:34+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5613",
                        "description": "",
                        "filename": "257880-6.jpg",
                        "ordering": "1",
                        "publicID": "xhrqdwiwytp8kifyfvin",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "131215",
                        "createTime": "2018-06-04T09:20:45+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5614",
                        "description": "",
                        "filename": "257880-8.jpg",
                        "ordering": "2",
                        "publicID": "q83brxogneoldssayvpe",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "75764",
                        "createTime": "2018-06-04T09:20:56+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5615",
                        "description": "",
                        "filename": "257880-9.jpg",
                        "ordering": "3",
                        "publicID": "fi4lhtvnusftsirszf7x",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "55487",
                        "createTime": "2018-06-04T09:21:07+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5616",
                        "description": "",
                        "filename": "257880-10.jpg",
                        "ordering": "4",
                        "publicID": "tllknjcpcb4ydj6iya9b",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "53206",
                        "createTime": "2018-06-04T09:21:18+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5617",
                        "description": "",
                        "filename": "257880.jpg",
                        "ordering": "5",
                        "publicID": "e9wg34mwif6zubt7kflx",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "68897",
                        "createTime": "2018-06-04T09:21:29+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5618",
                        "description": "",
                        "filename": "257880-2.jpg",
                        "ordering": "6",
                        "publicID": "var4uf0tkltfwf4hfqms",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "104671",
                        "createTime": "2018-06-04T09:21:40+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    },
                    {
                        "imageID": "5619",
                        "description": "",
                        "filename": "257880-2-2.jpg",
                        "ordering": "7",
                        "publicID": "qencqxmsjwbcolnztros",
                        "baseImageURL": "https://res.cloudinary.com/lightspeed-retail/image/upload/",
                        "size": "79981",
                        "createTime": "2018-06-04T09:21:51+00:00",
                        "timeStamp": "2018-08-31T18:28:03+00:00",
                        "itemID": "2898",
                        "itemMatrixID": "0"
                    }
                ]
            }
  • jamesratcliffejamesratcliffe Posts: 141Administrator, Lightspeed Staff moderator
    @gregarican You can specify the ordering field in the 'data' field of the POST data:
    {"description": "Test Image", "ordering": 1}
    If you didn't set this, use the imageID to order the images based on when they were added. The timeStamp can change, so it might not give you the results you want.

    Any images added in the UI will have their 'ordering' field set based on their position in the grid, but existing images won't be affected.

    If a user rearranges the images in the UI, all the images on the item will have their 'ordering' fields set based on their new positions in the grid.
    James Ratcliffe
    API Integrations Specialist
    Lightspeed HQ
  • gregaricangregarican Posts: 82Member ✭
    Currently I am looking at both the ImageID and the CreateTime (sorry, typoed TimeStamp by accident earlier) to determine the ordering for the stragglers. Thanks for the feedback and clarification!
  • jamesratcliffejamesratcliffe Posts: 141Administrator, Lightspeed Staff moderator
    You’re welcome.
    James Ratcliffe
    API Integrations Specialist
    Lightspeed HQ
Sign In or Register to comment.