What is the difference between UPC and object id?

I am trying to retrieve product information based on barcode/UPC and finding myself confused by the API documentation. I am a beginner for programming.

Is there a way to do this? I read here but im clueless as to where the id came from.
GET /v2/catalog/object/{object_id} - Square API Reference

:wave: With Square each catalog object will have a unique object_id that is generated by Square. This ID is what is used in the GET /v2/catalog/object/{object_id}. The UPC of an item_variation is a field within the item_variation_data. :slightly_smiling_face:

1 Like

Thanks Bryan. Your description and link helped a lot. Under the description for UPC it says “This is a searchable attribute for use in applicable query filters.”

Could you point me in the right direction for how to search it?

Yeah, you will need to use SearchCatalogObjects with this request body to search items by sku. :slightly_smiling_face:

{
    "object_types": [
      "ITEM",
      "ITEM_VARIATION"
    ],
    "query": {
      "prefix_query": {
        "attribute_name": "sku",
        "attribute_prefix": "12345678"
      }
    }
  }

Thanks. I moved on to playing with SearchCatalogItems
which should be able to search by upc rather than sku right? But I’m running into a problem with adding a upc value to the sandbox items (I can’t figure out how). What I’m trying to do is use UPC to grab some item details essentially, and I think the code below should work with upc: 123456789012 for example, if I can assign the value to a test item

result = client.catalog.search_catalog_items(
  body = {
    "text_filter": "123456789012"
  }
)

Currently the UPC isn’t currently available in sandbox. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

1 Like

Ok got it. But it should work in production then?
And following that, can I effectively code it in sandbox with sku then switch to upc text_filter for production?

Yes, that’s correct. Or you can use the following with SearchCatalogObjects moving to production. :slightly_smiling_face:

{
  "object_types": [
    "ITEM", "ITEM_VARIATION"
  ],
  "query": {
    "prefix_query": {
      "attribute_name": "upc",
      "attribute_prefix": "12345678"
    }
  },
  "limit": 100
}
1 Like