Fixing Zapier webhook for Upsert Catalog Object endpoint

Hi there, I am trying to create a webhook in Zapier to create a catalog item in Square. Here’s some things to know…

  • In the code below, the double curly braces e.g. {{236150602__Price for Square API}} represent dynamic data fields in Zapier.
    I believe that when the webhook is triggered, those values are replaced with the actual data, otherwise the non-expressed values like {{236150602__Price for Square API}} would be looking at that opening curly brace as an open bracket.

  • My problem is that I am getting a 400 response in Zapier which unhelpfully tells me that “Failed to create a request in Webhooks by Zapier. Field must be set (HTTP Status Code: 400)” This sounds like a required field isn’t filled in, but it doesn’t tell me which one.

  • I’ve looked through the endpoint and I think I have the required fields below, but this is my first foray into APIs, so reading the docs is a little heavy!

Could anyone look at the below and let me know if there’s anything obvious from a syntax or missing data point of view?

Equally if anyone has any Zapier experience, I would happily pay for your expertise to get this finished!

{
"idempotency_key": "{{236150602__id}}{{zap_meta_timestamp}}",
  "batches": [
{  "objects": [
{
    "type": "ITEM",
    "id": "#{{236150602__id}}",
    "updated_at": "{{zap_meta_timestamp}}",
    "created_at": "{{zap_meta_timestamp}}",
    "present_at_all_locations": false,
    "present_at_location_ids": [
      "LJCAQQ7GEX7JZ"
    ],
    "item_data": {
      "name": "{{236150602__Name}}",
      "is_taxable": true,
      "variations": [
        {
          "type": "ITEM_VARIATION",
          "id": "#NEW{{236150602__id}}",
          "is_deleted": false,
          "present_at_all_locations": false,
          "present_at_location_ids": [
            "LJCAQQ7GEX7JZ"
          ],
          "item_variation_data": {
            "item_id": "{{236150602__id}}",
            "name": "{{236150602__Name}}",
            "sku": "{{236150602__EAN for Automation}}",
            "upc": "{{236150602__EAN for Automation}}",
            "ordinal": 1,
            "pricing_type": "FIXED_PRICING",
            "price_money": {
              "amount": {{236150602__Price for Square API}},
              "currency": "GBP"
            },
            "location_overrides": [
              {
                "location_id": "LJCAQQ7GEX7JZ",
                "track_inventory": true
              }
            ],
            "track_inventory": true,
            "sellable": true,
            "stockable": true,
            "default_unit_cost": {
              "amount": {{236150602__Cost Price for Square API}},
              "currency": "GBP"
            },
                "item_variation_vendor_info_data": {
                  "ordinal": 1,
                  "sku": "{{236150602__Brand ID}}",
                  "price_money": {
                    "amount": {{236150602__Price for Square API}},
                    "currency": "GBP"
                  },
                  "item_variation_id": "#NEW{{236150602__id}}",
                  "vendor_id": "{{236150602__Brand ID}}"
                }
              }
          }
      ],
      "product_type": "REGULAR",
      "skip_modifier_screen": false,
      "ecom_available": false,
      "ecom_visibility": "UNINDEXED",
      "categories": [
        {
          "id": "{{236150602__Square Category ID (from Categories)}}",
          "ordinal": "{{236150602__Square Ordinal Depth (from Categories)}}"
        }
      ],
      "reporting_category": {
        "id": "{{236150602__Square Category ID (from Categories)}}",
        "ordinal": "{{236150602__Square Ordinal Depth (from Categories)}}"
      }
    }
  }]
}]}

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
https://developer.squareup.com/docs/squarebridge/business-central/onboard

Additional Documentation

Payments API Webhooks
Use Webhooks to Integrate with a Payroll System
Use Customer Webhooks

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

I took a look at the API Logs for your application. Its calling the Catalog API however the requests to UpsertCatalogObject are failing because the body of the request isn’t correct. Have you looked at using our API Explorer to help build the API requests? It should look something like:

{
    "idempotency_key": "{{$guid}}",
    "object": {
        "type": "ITEM",
        "id": "#Coffee",
        "present_at_all_locations": true,
        "item_data": {
            "name": "Coffee",
            "description": "Hot Bean Juice",
            "variations": [
                {
                    "type": "ITEM_VARIATION",
                    "id": "#Coffee_Regular",
                    "present_at_all_locations": true,
                    "item_variation_data": {
                        "item_id": "#Coffee",
                        "name": "Regular",
                        "pricing_type": "FIXED_PRICING",
                        "price_money": {
                            "amount": 250,
                            "currency": "USD"
                        }
                    }
                },
                {
                    "type": "ITEM_VARIATION",
                    "id": "#Coffee_Large",
                    "present_at_all_locations": true,
                    "item_variation_data": {
                        "item_id": "#Coffee",
                        "name": "Large",
                        "pricing_type": "FIXED_PRICING",
                        "price_money": {
                            "amount": 350,
                            "currency": "USD"
                        }
                    }
                }
            ]
        }
    }
}

:slightly_smiling_face:

Hey Bryan,

Thanks for coming back to me. I’m getting closer, but not fixed.

This is the body now:

{
"idempotency_key": "{{240283442__id}}{{zap_meta_timestamp}}",
  "batches": [
{  "objects": [
{
    "type": "ITEM",
    "id": "#{{240283442__id}}",
    "updated_at": "{{zap_meta_timestamp}}",
    "created_at": "{{zap_meta_timestamp}}",
    "present_at_all_locations": false,
    "present_at_location_ids": [
      "LJCAQQ7GEX7JZ"
    ],
    "item_data": {
      "name": "{{240283442__Name}}",
      "is_taxable": true,
      "variations": [
        {
          "type": "ITEM_VARIATION",
          "id": "#NEW{{240283442__id}}",
          "is_deleted": false,
          "present_at_all_locations": false,
          "present_at_location_ids": [
            "LJCAQQ7GEX7JZ"
          ],
          "item_variation_data": {
            "item_id": "#{{240283442__id}}",
            "name": "{{240283442__Name}}",
            "sku": "{{240283442__EAN for Automation}}",
            "upc": "{{240283442__EAN for Automation}}",
            "ordinal": 1,
            "pricing_type": "FIXED_PRICING",
            "price_money": {
              "amount": {{240283442__Price for Square API}},
              "currency": "GBP"
            },
            "location_overrides": [
              {
                "location_id": "LJCAQQ7GEX7JZ",
                "track_inventory": true
              }
            ],
            "track_inventory": true,
            "sellable": true,
            "stockable": true,
            "default_unit_cost": {
              "amount": {{240283442__Cost Price for Square API}},
              "currency": "GBP"
            },
                "item_variation_vendor_info_data": {
                  "ordinal": 1,
                  "sku": "{{240283442__Brand ID}}",
                  "price_money": {
                    "amount": {{240283442__Price for Square API}},
                    "currency": "GBP"
                  },
                  "item_variation_id": "#NEW{{240283442__id}}",
                  "vendor_id": "{{240283442__Brand ID}}"
                }
              }
          }
      ],
      "product_type": "REGULAR",
      "skip_modifier_screen": false,
      "ecom_available": false,
      "ecom_visibility": "UNINDEXED",
      "categories": [
        {
          "id": "{{240283442__Square Category ID (from Categories)}}",
          "ordinal": {{240283442__Square Ordinal Depth (from Categories)}}
        }
      ],
      "reporting_category": {
        "id": "{{240283442__Square Category ID (from Categories)}}",
        "ordinal": {{240283442__Square Ordinal Depth (from Categories)}}
      }
    }
  }]
}]}

and I’m getting this response message, although I can’t tell what object it is referring to?

Invalid object: Invalid Object with Id: BTDVIKPPML6ICTCJYY53PM2P [merchant_token=MLMJJ711P7Y63] duplicate int value 1 with string value 5V6I5LHTPIAK4Z65JQIMTQKU found for attribute SQ_ADDITIONAL_CATEGORY (obj ObjectWithAttributes{ Id:51538435,Token:“BTDVIKPPML6ICTCJYY53PM2P”,MasterCatalogId:999567,Type:1(ITEM),CreatedBy:127298844,Timestamp:1714203468467(2024-04-27 07:37:48.467 +0000 UTC) Ordinal:0 Attributes:{ Attribute{Id:532556240,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:113,DefinitionToken:“SQ_3”,StringValue:“One more item”,CreatedBy:127298844} Attribute{Id:532556241,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:120,DefinitionToken:“SQ_ADDITIONAL_CATEGORY”,IntValue:1,StringValue:“5V6I5LHTPIAK4Z65JQIMTQKU”,CreatedBy:127298844} Attribute{Id:532556242,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:56,DefinitionToken:“SQ_COGS_E”,IntValue:1,CreatedBy:127298844} Attribute{Id:532556243,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:153,DefinitionToken:“SQ_10”,IntValue:0,CreatedBy:127298844} Attribute{Id:532556244,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:87,DefinitionToken:“SQ_ITAX”,IntValue:1,CreatedBy:127298844} Attribute{Id:532556245,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:4291255,DefinitionToken:“SQ_IS_ARCHIVED”,IntValue:0,CreatedBy:127298844} Attribute{Id:532556440,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:51,DefinitionToken:“SQ_ECOM_AVAIL”,IntValue:0,CreatedBy:127298907} Attribute{Id:532556441,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:53,DefinitionToken:“SQ_ECOM_VISIBILITY”,IntValue:1,CreatedBy:127298907} Attribute{Id:532556442,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:4677354,DefinitionToken:“SQ_REQUIRES_SUBSCRIPTION_TO_SELL”,IntValue:0,CreatedBy:127298907} Attribute{Id:532557224,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:210,DefinitionToken:“SQ_VIS”,IntValue:1,CreatedBy:127299148} Attribute{Id:532557226,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:3096504,DefinitionToken:“SQ_FPSI”,StringValue:“fprefs_127zdfwvpdfrilm32ppxehbwb”,CreatedBy:127299148} Attribute{Id:532557227,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:246,DefinitionToken:“SQ_FPPI”,StringValue:“fprefs_127zdfwvowpudeu9dhbadhny3”,CreatedBy:127299148} Attribute{Id:532557228,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:245,DefinitionToken:“SQ_FPDI”,StringValue:“fprefs_127zdfwvnu9dmy66um0oxn4or”,CreatedBy:127299148} Attribute{Id:532557229,MasterCatalogId:999567,ObjectId:51538435,ObjectType:1(ITEM),DefinitionId:3096505,DefinitionToken:“SQ_FPDII”,StringValue:“fprefs_127zdfwvodgyra2646gxrahyz”,CreatedBy:127299148} } }) (existing object token ZWMEROJQWN7DZ7QSXWBIENMK). (HTTP Status Code: 400)

Looks like this is due to a duplicate category being passed in. As for the other fields they are read only fields and shouldn’t be set when creating a new item. :slightly_smiling_face:

Are you still facing this issue?

Hey @Bryan-Square and @goalight912 I am still having this issue.

The first time I run the automation, it works, but the second and subsequent times I get this issue.

I want to create new items to go in existing categories, not create new categories. Can you help me out with the syntax of that?

Thanks!

{
    "batches": [
      {
        "objects": [
          {
            "id": "#{{1.id}}",
            "type": "ITEM",
            "present_at_all_locations": false,
            "present_at_location_ids": [
              "LJCAQQ7GEX7JZ"
            ],
            "is_deleted": false,
            "item_data": {
              "categories": [
                {
                  "ordinal": {{1.`Square Ordinal Depth (from Categories)`[]}},
                  "id": "{{1.`Square Category ID (from Categories)`[]}}"
                }
              ],
              "reporting_category": {
                "id": "{{1.`Square Category ID (from Categories)`[]}}",
                "ordinal": {{1.`Square Ordinal Depth (from Categories)`[]}}
              },
              "variations": [
                {
                  "id": "#NEW{{1.id}}",
                  "type": "ITEM_VARIATION",
                  "item_variation_data": {
                    "item_id": "#{{1.id}}",
                    "price_money": {
                      "amount": {{round(1.`Price for Square API`)}},
                      "currency": "GBP"
                    },
                    "pricing_type": "FIXED_PRICING",
                    "sku": "{{1.`EAN for Automation`}}",
                    "upc": "{{1.`EAN for Automation`}}"
                  },
                  "present_at_all_locations": false,
                  "present_at_location_ids": [
                    "LJCAQQ7GEX7JZ"
                  ]
                }
              ],
              "is_taxable": {{1.Taxable}},
              "is_archived": false,
              "product_type": "REGULAR",
              "name": "{{1.Name}}"
            }
          }
        ]
      }
    ],
    "idempotency_key": "{{1.id}}{{timestamp}}"
  }

What’s different about the subsequent requests that’s causing it to fail? What does your API Logs showing that’s causing the error? :slightly_smiling_face:

I’m sorry @Bryan-Square I don’t fully understand the question. Even when I try in the Square API explorer, if I do it the first time and add a new product, it works - 200! Score!

But if I generate a new idempotency key, change the IDs by a digit i.e. from #1234 to #12345, and variation ID from #NEW1234 to #NEW12345, change the name etc, it comes up with the 400 response that I’m rapidly turning grey over :sweat_smile:

{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "Invalid object: Invalid Object with Id: 6PKADLDS5SRWPM4VDTIBO7YN\n[merchant_token=MLMJJ711P7Y63] duplicate int value 1 with string value 66CUUBKJ2Z2ZCLDF3OHAI6OF found for attribute SQ_COGS_MCID (obj ObjectWithAttributes{\n    Id:52554890,Token:\"6PKADLDS5SRWPM4VDTIBO7YN\",MasterCatalogId:999567,Type:1(ITEM),CreatedBy:133338090,Timestamp:1716332629681(2024-05-21 23:03:49.681 +0000 UTC)\n    Ordinal:0\n    Attributes:{\n        Attribute{Id:549119258,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:153,DefinitionToken:\"SQ_10\",IntValue:0,CreatedBy:133338090}\n        Attribute{Id:549119259,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:113,DefinitionToken:\"SQ_3\",StringValue:\"New Mega Thing\",CreatedBy:133338090}\n        Attribute{Id:549119260,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:56,DefinitionToken:\"SQ_COGS_E\",IntValue:1,CreatedBy:133338090}\n        Attribute{Id:549119261,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:104,DefinitionToken:\"SQ_COGS_MCID\",IntValue:1,StringValue:\"66CUUBKJ2Z2ZCLDF3OHAI6OF\",CreatedBy:133338090}\n        Attribute{Id:549119262,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:87,DefinitionToken:\"SQ_ITAX\",IntValue:1,CreatedBy:133338090}\n        Attribute{Id:549119263,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:4291255,DefinitionToken:\"SQ_IS_ARCHIVED\",IntValue:0,CreatedBy:133338090}\n        Attribute{Id:549119684,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:51,DefinitionToken:\"SQ_ECOM_AVAIL\",IntValue:0,CreatedBy:133338304}\n        Attribute{Id:549119685,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:53,DefinitionToken:\"SQ_ECOM_VISIBILITY\",IntValue:1,CreatedBy:133338304}\n        Attribute{Id:549119686,MasterCatalogId:999567,ObjectId:52554890,ObjectType:1(ITEM),DefinitionId:4677354,DefinitionToken:\"SQ_REQUIRES_SUBSCRIPTION_TO_SELL\",IntValue:0,CreatedBy:133338304}\n    }\n}) (existing object token UB6SBE647CDMQG7HAIXA6MLU)."
    }
  ]
}

(here was my input)

{
    "idempotency_key": "9fa8353b-bab8-4787-82c5-2c65ed4763cc",
    "object": {
      "id": "#123412341234123412341234123412341235",
      "type": "ITEM",
      "item_data": {
        "variations": [
          {
            "id": "#NEW123412341235",
            "type": "ITEM_VARIATION",
            "item_variation_data": {
              "price_money": {
                "amount": 500,
                "currency": "GBP"
              },
              "pricing_type": "FIXED_PRICING",
              "sellable": true,
              "sku": "8998888",
              "stockable": true,
              "track_inventory": true,
              "upc": "8998888",
              "item_id": "#123412341234123412341234123412341235"
            }
          }
        ],
        "categories": [
          {
            "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
            "ordinal": 1
          }
        ],
        "is_taxable": true,
        "name": "New Mega Thing 2",
        "product_type": "REGULAR",
        "reporting_category": {
          "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
          "ordinal": 1
        }
      }
    }
  }

Here was the successful 200 request:

{
  "idempotency_key": "c0b663dc-ca29-45b6-bb3d-a6bb3c895a8c",
  "object": {
    "id": "#123412341234123412341234123412341234",
    "type": "ITEM",
    "item_data": {
      "variations": [
        {
          "id": "#NEW123412341234",
          "type": "ITEM_VARIATION",
          "item_variation_data": {
            "price_money": {
              "amount": 500,
              "currency": "GBP"
            },
            "pricing_type": "FIXED_PRICING",
            "sellable": true,
            "sku": "8988888",
            "stockable": true,
            "track_inventory": true,
            "upc": "8988888",
            "item_id": "#123412341234123412341234123412341234"
          }
        }
      ],
      "categories": [
        {
          "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
          "ordinal": 1
        }
      ],
      "is_taxable": true,
      "name": "New Mega Thing",
      "product_type": "REGULAR",
      "reporting_category": {
        "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
        "ordinal": 1
      }
    }
  }
}

and the response…

 {
  "catalog_object": {
    "type": "ITEM",
    "id": "6PKADLDS5SRWPM4VDTIBO7YN",
    "updated_at": "2024-05-21T23:02:36.135Z",
    "created_at": "2024-05-21T23:02:36.135Z",
    "version": 1716332556135,
    "is_deleted": false,
    "present_at_all_locations": true,
    "item_data": {
      "name": "New Mega Thing",
      "is_taxable": true,
      "variations": [
        {
          "type": "ITEM_VARIATION",
          "id": "SR6VZANIVMJQP4R255HHD3ML",
          "updated_at": "2024-05-21T23:02:36.135Z",
          "created_at": "2024-05-21T23:02:36.135Z",
          "version": 1716332556135,
          "is_deleted": false,
          "present_at_all_locations": true,
          "item_variation_data": {
            "item_id": "6PKADLDS5SRWPM4VDTIBO7YN",
            "name": "",
            "sku": "8988888",
            "upc": "8988888",
            "ordinal": 0,
            "pricing_type": "FIXED_PRICING",
            "price_money": {
              "amount": 500,
              "currency": "GBP"
            },
            "location_overrides": [
              {
                "location_id": "LJCAQQ7GEX7JZ",
                "sold_out": true
              }
            ],
            "track_inventory": true,
            "sellable": true,
            "stockable": true
          }
        }
      ],
      "product_type": "REGULAR",
      "categories": [
        {
          "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
          "ordinal": 1
        }
      ],
      "is_archived": false,
      "reporting_category": {
        "id": "66CUUBKJ2Z2ZCLDF3OHAI6OF",
        "ordinal": 1
      }
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#123412341234123412341234123412341234",
      "object_id": "6PKADLDS5SRWPM4VDTIBO7YN"
    },
    {
      "client_object_id": "#NEW123412341234",
      "object_id": "SR6VZANIVMJQP4R255HHD3ML"
    }
  ]
}

I was able to replicate this error and have reached out to the team. :slightly_smiling_face:

OMG @Bryan-Square , I think I know what the issue is - I just removed the ordinal from underneath the categories and it worked! Did I have that wrong maybe?

Yep, according to the team the ordinal is the issue. Glad you figured it out! :slightly_smiling_face:

Thanks Bryan - got there in the end :nerd_face: