# Upsert Catalog Object

**URL:** <https://developer.squareup.com/forums/t/upsert-catalog-object/6393>\
**Category:** Questions\
**Tags:** catalog-api, sandbox\
**Created:** [July 4, 2022, 12:02pm UTC](https://developer.squareup.com/forums/t/upsert-catalog-object/6393 "2022-07-04T12:02:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zedd\_D1abl0](https://avatars.discourse-cdn.com/v4/letter/z/35a633/32.png) [@zedd\_D1abl0](https://developer.squareup.com/forums/u/zedd_D1abl0)\
**Post date:** [July 4, 2022, 12:02pm UTC](https://developer.squareup.com/forums/t/upsert-catalog-object/6393/1 "2022-07-04T12:02:30Z")

</div>

Hi All,

I’m a bit of a beginner in the grand scheme of things, and I’m using an unsupported language to do my integration, but I feel like something obvious is missing and after re-reading all the API documentation, I still have no idea what is going wrong.

Working off the API documentation, but with my own Item, I generate a JSON request such as:

```auto
curl https://connect.squareupsandbox.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": "24bf222c-21a8-4bd2-9097-b7e7ec3d2f36",
    "object": {
      "type": "ITEM",
      "id": "#1298498081",
      "is_deleted": false,
      "present_at_all_locations": true,
      "item_data": {
        "description": "Grey Cat",
        "name": "Grey Cat",
        "available_online": true,
        "available_for_pickup": true,
        "category_id": "P4KZKJNAOWNT7JIU6GRTWNAL",
        "image_ids": [
          "HSVH4KFM2RWCAPUFOB2EWJ3T"
        ],
        "tax_ids": [
          "AUSSALESTAXMLQZ38K6X6A1N"
        ],
        "product_type": "REGULAR",
        "variations": [
          {
            "type": "ITEM_VARIATION",
            "id": "#1298main",
            "is_deleted": false,
            "item_variation_data": {
              "image_ids": [
                "HSVH4KFM2RWCAPUFOB2EWJ3T"
              ],
              "inventory_alert_type": "NONE",
              "item_id": "#1298498081",
              "name": "Grey Cat",
              "pricing_type": "FIXED_PRICING",
              "price_money": {
                "amount": 1989,
                "currency": "AUD"
              },
              "sellable": true,
              "stockable": true,
              "stockable_conversion": {
                "nonstockable_quantity": "0",
                "stockable_quantity": "1",
                "stockable_item_variation_id": "#1298main"
              },
              "inventory_alert_threshold": 0
            }
          }
        ]
      },
      "version": 0
    }
  }'

```

and I get the following error:

```auto
{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "BAD_REQUEST",
      "detail": "Bad request."
    }
  ]
}

```

BAD\_REQUEST doesn’t really give me any guidance as to what the problem is, but I got this far by drilling through the various errors the API threw back at me. Without “item\_data” I get a “Missing Item Data” error. Without a “variations”, I get a “Variation missing” error. If I continue down this path, I get various errors about the lack of category, lack of stockable\_conversion, lack of inventory\_alert\_type, etc.

I tried going off the example given at [https://developer.squareup.com/reference/square/catalog/upsert-catalog-object](https://developer.squareup.com/reference/square/catalog/upsert-catalog-object):

```auto
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": "af3d1afc-7212-4300-b463-0bfc5314a5ae",
    "object": {
      "id": "#Cocoa",
      "type": "ITEM",
      "item_data": {
        "abbreviation": "Ch",
        "description": "Hot Chocolate",
        "name": "Cocoa",
        "variations": [
          {
            "id": "#Small",
            "type": "ITEM_VARIATION",
            "item_variation_data": {
              "item_id": "#Cocoa",
              "name": "Small",
              "pricing_type": "VARIABLE_PRICING"
            }
          },
          {
            "id": "#Large",
            "type": "ITEM_VARIATION",
            "item_variation_data": {
              "item_id": "#Cocoa",
              "name": "Large",
              "pricing_type": "FIXED_PRICING",
              "price_money": {
                "amount": 400,
                "currency": "USD"
              }
            }
          }
        ]
      }
    }
  }'

```

But it appears to be missing a heap of the fields I’ve been told are required by the API.

Sorry if this seems rambling, but I’ve spent about 6 hours trying to troubleshoot a JSON object and the request, and I have no more information on what’s missing. I’ve tried looking for similar queries, but there has been nothing obviously analogous to my situation.

---

<div class="post-metadata">

**Author:** ![zedd\_D1abl0](https://avatars.discourse-cdn.com/v4/letter/z/35a633/32.png) [@zedd\_D1abl0](https://developer.squareup.com/forums/u/zedd_D1abl0)\
**Post date:** [July 4, 2022, 12:22pm UTC](https://developer.squareup.com/forums/t/upsert-catalog-object/6393/2 "2022-07-04T12:22:04Z")

</div>

This can be closed. It turns out that I’m just a bad developer. The demo does indeed work, and it was a secret idiosyncrasy to do with the way Golang deals with nil values and “OmitEmpty”.

For anyone who trips over this and is trying to do the dumb things I was doing, make sure you use pointers to your structs you want to be omitted. A struct is always initialized if the structure defines it. But pointers aren’t, and require you to initialize them. They convert to JSON properly, but they’re also omitted if they aren’t initialized. The key one that was killing this was:

```auto
Stockable_Conversion *CatalogStockConversion `json:"stockable_conversion,omitempty"`

```

Without the “\*”, the struct is always in place. Adding that single “\*” allows the struct to become a pointer, which fixes the omitempty if you don’t initialize it, fixing the universe. And it only took 6 hours and 12 minutes…

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [July 5, 2022, 5:25pm UTC](https://developer.squareup.com/forums/t/upsert-catalog-object/6393/3 "2022-07-05T17:25:27Z")

</div>

Glad to hear you figured it out! 🙂
