Update custom_attribute_values in a ITEM

Hello. I would like to update the custom_attribute_values but I get a generic error. What is the right way to update the custom attribute in ITEM ?

Request:

curl https://connect.squareupsandbox.com/v2/catalog/batch-upsert \
  -X POST \
  -H 'Square-Version: 2021-11-17' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "idempotency_key": "square61ba2a15614bd",
  "batches": [
    {
      "objects": [
        {
          "id": "H5QPX4M7JTSLRAECDXN4LIOP",
          "type": "ITEM",
          "item_data": {
            "product_type": "REGULAR",
            "name": "PS5 - PIM",
            "description": "Awesome game - PIM",
            "variations": [
              {
                "id": "VJONTMD4MWLCK4U6NIH2MRBW",
                "type": "ITEM_VARIATION",
                "item_variation_data": {
                  "name": "PS5 - PIM",
                  "sku": "PS5-PIM",
                  "ordinal": 0,
                  "track_inventory": true,
                  "pricing_type": "FIXED_PRICING",
                  "price_money": {
                    "amount": 8900,
                    "currency": "USD"
                  },
                  "item_id": "H5QPX4M7JTSLRAECDXN4LIOP"
                },
                "version": 1639589790562
              }
            ],
            "category_id": "2XTOFYBWOTCV7RWBKGNQDHHX"
          },
          "present_at_all_locations": true,
          "version": 1639589790562,
          "custom_attribute_values": {
            "id_3": {
              "selection_uid_values": [
                "#brazil"
              ]
            },
            "id_2": {
              "selection_uid_values": [
                "#extrajoystick"
              ]
            },
            "id_1": {
              "string_value": "Sony Entertainment"
            }
          }
        }
      ]
    }
  ]
}'

Response error:

{"errors":[{"category":"API_ERROR","code":"INTERNAL_SERVER_ERROR","detail":"An internal error has occurred, and the API was unable to service your request."}]}

My custom attribute definition objects:

{
  "objects": [
    {
      "type": "CUSTOM_ATTRIBUTE_DEFINITION",
      "id": "IGAI3QXU6TCIDETATG7OL2JD",
      "updated_at": "2021-12-15T17:36:30.562Z",
      "created_at": "1970-01-19T23:26:29.79Z",
      "version": 1639589790562,
      "is_deleted": false,
      "present_at_all_locations": true,
      "custom_attribute_definition_data": {
        "type": "SELECTION",
        "name": "Country PIM",
        "source_application": {
          "application_id": "sandbox-sq0idb-c1GGOzrCQTSYdhxEQLz9mA",
          "name": "Sandbox for sq0idp-kyWNphVz8Z2udgya-GZrxQ"
        },
        "allowed_object_types": [
          "ITEM",
          "ITEM_VARIATION"
        ],
        "seller_visibility": "SELLER_VISIBILITY_READ_WRITE_VALUES",
        "app_visibility": "APP_VISIBILITY_HIDDEN",
        "selection_config": {
          "max_allowed_selections": 1,
          "allowed_selections": [
            {
              "uid": "WRTMSKMUHO2IZF5GWJ3PMW2P",
              "name": "Brazil"
            },
            {
              "uid": "B47TXDZDEC4IAUTLRK7EI4HI",
              "name": "Canada"
            },
            {
              "uid": "MGVL7ETE52BYKJCTZ4BMD52M",
              "name": "China"
            },
            {
              "uid": "5LSVFM2WZ3QIHA7TOKBOJOV3",
              "name": "USA"
            }
          ]
        },
        "key": "id_3"
      }
    },
    {
      "type": "CUSTOM_ATTRIBUTE_DEFINITION",
      "id": "4HID3QT5G6WETEYCLG3MWEKR",
      "updated_at": "2021-12-15T17:36:30.562Z",
      "created_at": "1970-01-19T23:26:29.79Z",
      "version": 1639589790562,
      "is_deleted": false,
      "present_at_all_locations": true,
      "custom_attribute_definition_data": {
        "type": "SELECTION",
        "name": "Extra Options PIM",
        "source_application": {
          "application_id": "sandbox-sq0idb-c1GGOzrCQTSYdhxEQLz9mA",
          "name": "Sandbox for sq0idp-kyWNphVz8Z2udgya-GZrxQ"
        },
        "allowed_object_types": [
          "ITEM",
          "ITEM_VARIATION"
        ],
        "seller_visibility": "SELLER_VISIBILITY_READ_WRITE_VALUES",
        "app_visibility": "APP_VISIBILITY_HIDDEN",
        "selection_config": {
          "max_allowed_selections": 5,
          "allowed_selections": [
            {
              "uid": "WERVUCCNGEDNB7UBG7PQZDCX",
              "name": "External HD"
            },
            {
              "uid": "OGVL3JWABVFJZIXUM7K6VTV6",
              "name": "Extra Joystick"
            },
            {
              "uid": "XDQ23DA4XVFURIPFWU2TDPLL",
              "name": "PSN PLUS"
            },
            {
              "uid": "R3GMGBK7AIUNAY77UX4YFO7Q",
              "name": "USB Cable"
            }
          ]
        },
        "key": "id_2"
      }
    },
    {
      "type": "CUSTOM_ATTRIBUTE_DEFINITION",
      "id": "HHSWNX4EXIUS6WZMRSUKWOCZ",
      "updated_at": "2021-12-15T17:36:30.562Z",
      "created_at": "1970-01-19T23:26:29.79Z",
      "version": 1639589790562,
      "is_deleted": false,
      "present_at_all_locations": true,
      "custom_attribute_definition_data": {
        "type": "STRING",
        "name": "Brand PIM",
        "source_application": {
          "application_id": "sandbox-sq0idb-c1GGOzrCQTSYdhxEQLz9mA",
          "name": "Sandbox for sq0idp-kyWNphVz8Z2udgya-GZrxQ"
        },
        "allowed_object_types": [
          "ITEM",
          "ITEM_VARIATION"
        ],
        "seller_visibility": "SELLER_VISIBILITY_READ_WRITE_VALUES",
        "app_visibility": "APP_VISIBILITY_HIDDEN",
        "string_config": {
          "enforce_uniqueness": false
        },
        "key": "id_1"
      }
    }
  ]
}

:wave: Thanks for bringing this to our attention. The team is looking into this. Also in the future please redact the access token. They are secret. :slightly_smiling_face:

We see that the custom attribute on the item is using the ID for the attribute definition selection isn’t a valid id. We definitely aren’t returning the correct error message and the team is working on a fix. :slightly_smiling_face:

1 Like

Thank you Bryan, It solved my problem, when we update the attribute values, we need to put the ID instead of of the temporary ID.

Hello! I was trying to upsert/create a new item using the upsert catalog object API. The request turned out to have a 200 response and the item was created fine. However, it seems like the custom_attribute_values was not reflected/created correctly. In the following example, my custom attribute value “expiry-date” was set to be 20221231 in the request, but you can see that it was set to 0.0 in the json response. Is this a bug on Square’s end?

custom_attribute_values in request:

"custom_attribute_values": {
  "63c5f5f1-430e-4079-9879-80898e6cf310": {
    "boolean_value": false,
    "name": "expiry-date",
    "number_value": "20221231"
  }
},

custom_attribute_values in response:

"custom_attribute_values": {
  "Square:63c5f5f1-430e-4079-9879-80898e6cf310": {
    "name": "expiry-date",
    "custom_attribute_definition_id": "EMOUBMKM6N2GVRH67JGW375T",
    "type": "NUMBER",
    "number_value": "0.0",
    "key": "Square:63c5f5f1-430e-4079-9879-80898e6cf310"
  }
}

My custom attribute definition object for expiry-date:

{
  "objects": [
    {
      "type": "CUSTOM_ATTRIBUTE_DEFINITION",
      "id": "EMOUBMKM6N2GVRH67JGW375T",
      "updated_at": "2022-04-01T04:45:15.575Z",
      "created_at": "2022-03-11T05:58:25.724Z",
      "version": 1648788315575,
      "is_deleted": false,
      "present_at_all_locations": true,
      "custom_attribute_definition_data": {
        "type": "NUMBER",
        "name": "expiry-date",
        "source_application": {
          "application_id": "Square"
        },
        "allowed_object_types": [
          "ITEM",
          "ITEM_VARIATION"
        ],
        "seller_visibility": "SELLER_VISIBILITY_READ_WRITE_VALUES",
        "app_visibility": "APP_VISIBILITY_READ_WRITE_VALUES",
        "number_config": {
          "precision": 0
        },
        "key": "63c5f5f1-430e-4079-9879-80898e6cf310"
      }
    }
  ],
  "latest_time": "2022-07-07T23:18:26.852Z"
}

Full request:

curl https://connect.squareup.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2022-06-16' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "9b0b2689-8818-4bf1-9c81-62f785ec6ec3",
    "object": {
      "id": "#duplicate",
      "type": "ITEM",
      "is_deleted": false,
      "present_at_all_locations": false,
      "present_at_location_ids": [
        "LB5F8WYCHXM5V"
      ],
      "version": 1657015438005,
      "item_data": {
        "available_electronically": false,
        "available_for_pickup": false,
        "available_online": false,
        "category_id": "WEG4H64NYKZZSAZZQUIJK77N",
        "description": "xxx",
        "image_ids": [
          "JAUCWUL22HMOTRM2PJIOS6SX"
        ],
        "name": "xxx",
        "product_type": "REGULAR",
        "skip_modifier_screen": false,
        "tax_ids": [
          "EPUSQLNPY23CEEZH26SPLZVA"
        ],
        "variations": [
          {
            "id": "#duplicatee",
            "type": "ITEM_VARIATION",
            "category_data": {
              "name": "xxx"
            },
            "custom_attribute_values": {
              "63c5f5f1-430e-4079-9879-80898e6cf310": {
                "boolean_value": false,
                "name": "expiry-date",
                "number_value": "20221231"
              }
            },
            "image_data": {
              "caption": "Puffcorn (Salty)",
              "url": "https://items-images-production.s3.us-west-2.amazonaws.com/files/c4ca5493077ec98a4f05747821527b9ad372ff42/original.jpeg"
            },
            "is_deleted": false,
            "item_variation_data": {
              "inventory_alert_threshold": 5,
              "inventory_alert_type": "LOW_QUANTITY",
              "name": "50g",
              "price_money": {
                "amount": 350,
                "currency": "CAD"
              },
              "pricing_type": "FIXED_PRICING",
              "sellable": true,
              "sku": "318130007",
              "stockable": true,
              "track_inventory": true,
              "upc": "4710015118251"
            },
            "present_at_all_locations": false,
            "present_at_location_ids": [
              "LB5F8WYCHXM5V"
            ],
            "tax_data": {
              "applies_to_custom_amounts": true,
              "calculation_phase": "TAX_SUBTOTAL_PHASE",
              "enabled": true,
              "inclusion_type": "ADDITIVE",
              "name": "GST",
              "percentage": "5"
            },
            "version": 1657015438005
          }
        ]
      }
    }
  }'

Full response:

{
  "catalog_object": {
    "type": "ITEM",
    "id": "WBNBFGQJERVCSP66ZR46UHKF",
    "updated_at": "2022-07-07T10:36:39.719Z",
    "created_at": "2022-07-07T10:36:39.719Z",
    "version": 1657190199719,
    "is_deleted": false,
    "present_at_all_locations": false,
    "present_at_location_ids": [
      "LB5F8WYCHXM5V"
    ],
    "item_data": {
      "name": "xxx",
      "available_online": false,
      "available_for_pickup": false,
      "available_electronically": false,
      "category_id": "WEG4H64NYKZZSAZZQUIJK77N",
      "tax_ids": [
        "EPUSQLNPY23CEEZH26SPLZVA"
      ],
      "variations": [
        {
          "type": "ITEM_VARIATION",
          "id": "JRMWWCQPH6YXIFVG7X53VWK5",
          "updated_at": "2022-07-07T10:36:39.719Z",
          "created_at": "2022-07-07T10:36:39.719Z",
          "version": 1657190199719,
          "is_deleted": false,
          "custom_attribute_values": {
            "Square:63c5f5f1-430e-4079-9879-80898e6cf310": {
              "name": "expiry-date",
              "custom_attribute_definition_id": "EMOUBMKM6N2GVRH67JGW375T",
              "type": "NUMBER",
              "number_value": "0.0",
              "key": "Square:63c5f5f1-430e-4079-9879-80898e6cf310"
            }
          },
          "present_at_all_locations": false,
          "present_at_location_ids": [
            "LB5F8WYCHXM5V"
          ],
          "item_variation_data": {
            "item_id": "WBNBFGQJERVCSP66ZR46UHKF",
            "name": "50g",
            "sku": "318130007",
            "upc": "4710015118251",
            "ordinal": 0,
            "pricing_type": "FIXED_PRICING",
            "price_money": {
              "amount": 350,
              "currency": "CAD"
            },
            "location_overrides": [
              {
                "location_id": "LB5F8WYCHXM5V",
                "sold_out": true
              }
            ],
            "track_inventory": true,
            "inventory_alert_type": "LOW_QUANTITY",
            "inventory_alert_threshold": 5,
            "sellable": true,
            "stockable": true
          }
        }
      ],
      "product_type": "REGULAR",
      "skip_modifier_screen": false,
      "image_ids": [
        "JAUCWUL22HMOTRM2PJIOS6SX"
      ]
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#duplicate",
      "object_id": "WBNBFGQJERVCSP66ZR46UHKF"
    },
    {
      "client_object_id": "#duplicatee",
      "object_id": "JRMWWCQPH6YXIFVG7X53VWK5"
    }
  ]
}