Square API: Object version does not match latest database version

Viewed 108

I'm trying to use the following Square API endpoint to update an item, but I'm getting some errors. Here is the item that I'm trying to update.

{
  "type": "ITEM",
  "id": "7HXK6NVBDKSOK64CCAYZJ2KW",
  "updated_at": "2020-08-08T21:43:41.849Z",
  "version": 1596923021849,
  "is_deleted": false,
  "present_at_all_locations": false,
  "present_at_location_ids": [
    "1JZ5JTPBW0EXY"
  ],
  "item_data": {
    "name": "Hummus Plate",
    "description": "Olives, feta, tomatoes, tzatziki and warm pita.",
    "visibility": "PRIVATE",
    "category_id": "ARB5LTTDUSER6T66ZWYO65FL",
    "variations": [
      {
        "type": "ITEM_VARIATION",
        "id": "HBIHPLROOJUUNUSW3BZUDQ5J",
        "updated_at": "2020-08-08T21:40:14.581Z",
        "version": 1596922814581,
        "is_deleted": false,
        "present_at_all_locations": false,
        "present_at_location_ids": [
          "1JZ5JTPBW0EXY"
        ],
        "item_variation_data": {
          "item_id": "7HXK6NVBDKSOK64CCAYZJ2KW",
          "name": "Regular",
          "ordinal": 0,
          "pricing_type": "FIXED_PRICING",
          "price_money": {
            "amount": 1000,
            "currency": "USD"
          }
        }
      }
    ],
    "product_type": "REGULAR",
    "skip_modifier_screen": true,
    "ecom_available": false,
    "ecom_visibility": "UNINDEXED"
  }
}

Here the body content.

{
  "batches": [{
    "objects": [{
      "type": "ITEM_VARIATION",
      "id": "T6KKCATDIU2VV4BDBMVGML4W",
      "item_variation_data": {
        "item_id": "FNWWGFTBQWFAYK6JGBD3LDLD",
        "pricing_type": "FIXED_PRICING",
        "price_money": {
          "amount": 150,
          "currency": "USD"
        }
      }
    }]
  }],
  "idempotency_key": "61994762-3a6s-4b75-sf81-fdfaf"
}

Here is the error I'm getting:

**{
    "errors": [
        {
            "category": "INVALID_REQUEST_ERROR",
            "code": "VERSION_MISMATCH",
            "detail": "Object version does not match latest database version.",
            "field": "version"
        }
    ]
}**

enter image description here

I'm not sure what I'm doing wrong, but I appreciate any help I can get. Thank you in advance!

1 Answers

When updating a catalog object in Square, you need to provide the latest version number in the request.

{
  "batches": [{
    "objects": [{
      "type": "ITEM_VARIATION",
      "id": "T6KKCATDIU2VV4BDBMVGML4W",
      "version": "12345",
      "item_variation_data": {
        "item_id": "FNWWGFTBQWFAYK6JGBD3LDLD",
        "pricing_type": "FIXED_PRICING",
        "price_money": {
          "amount": 150,
          "currency": "USD"
        }
      }
    }]
  }],
  "idempotency_key": "61994762-3a6s-4b75-sf81-fdfaf"
}
Related