Understanding image_id attribute of `CatalogObject`

Good morning,

I’ve been working on understanding how to upload several CatalogImage instances registered to a given CatalogItem, in the Java SDK in particular. To do this, I intend to first upload the CatalogItem (wrapped within a CatalogObject instance, of course), retrieve its ID from the upsert response, and then, for every image, use the CreateCatalogImageRequest endpoint to supply both the image data and the ID that I got for the CatalogItem that I uploaded earlier. That way, I can “register” all the images to that item.

However, upon studying the relationship of the various IDs, I noticed that in CatalogObject, there exists an attribute (and accompanying accessor in the Java SDK) called image_id. I am not sure what the benefit of that id is, considering that the CatalogObject itself already has a unique id field. The Javadoc reads:

   /**
     * Getter for ImageId.
     * Identifies the `CatalogImage` attached to this `CatalogObject`.
     * @return Returns the String
     */
    @JsonGetter("image_id")
    public String getImageId() {
        return this.imageId;
    }

The use of “attached” makes this even weirder for me, because:

(1) If it is supposed to represent the id of the current CatalogObject which just so happens to embed a CatalogImage, why do we need it, given the other id field?

(2) If, on the other hand, it means that this ID is the ID of a CatalogImage that we separately uploaded and registered to the CatalogObject, why is there only one String ID instead of a List of those IDs?

Regards,

JF

There can only be one image per CatalogImage, so you won’t be able to upload several images to one specific object (although you could upload one for each variation object). The image_id would be present on the object that the image is attached to (whether it’s the parent item object, or the variation object). It allows you to know the image_id of whatever object you’re looking at. It would not be present on the image object itself.

Please let me know if I misunderstood or if you have additional questions!

So, if I understand correctly here, if I have a product that I want to POST on my Square Catalog, and I want to include, say, 5 images of that product, I need a minimum of 5 CatalogItemVariation instances? One per image? I say “minimum” because there might be more variations for different needs.

Yes, that’s correct. If you call CreateCatalogImage and use an object_id that already has an image associated, then the image_id would simply be overwritten.

1 Like