Set present locations for Item and Item Variation

Hello, I created this new topic to continue the conversation from the below topic:

In the API request I am specifying the present_at_all_locations, absent_at_location_ids, and present_at_location_ids for parent item object and item variation object. Am I doing anything wrong and if you can share an example API request that successfully updates the Item and Item Variation object’s present locations that would be great!

: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:

Additional Documentation

Use Custom Attributes for Locations
Locations API Requirements
Retrieve Inventory Quantities

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.

When you’re updating an item or item variation’s present locations, you should only specify either the present_at_all_locations, absent_at_location_ids, or present_at_location_ids field, not all of them at once.

If you want the item or item variation to be present at all locations, you should set present_at_all_locations to true and don’t specify the absent_at_location_ids and present_at_location_ids fields.

If you want the item or item variation to be absent at specific locations, you should set present_at_all_locations to true and specify the absent_at_location_ids field with the IDs of the locations where the item or item variation should be absent. Don’t specify the present_at_location_ids field.

If you want the item or item variation to be present only at specific locations, you should set present_at_all_locations to false and specify the present_at_location_ids field with the IDs of the locations where the item or item variation should be present. Don’t specify the absent_at_location_ids field.

Remember to use the UpsertCatalogObject endpoint of the Catalog API to update the item or item variation.

This answer was reviewed by @Bryan-Square.

Actually, I don’t want an item and item variation to be present at future locations. I am using BatchUpsertCatalogObject endpoint of the Catalog API to update the item or item variation.

Also, could you please provide a sample API request that updates the present locations of item and item variation?

Okay then the object you pass in the upsert request should look similar to this object:

{
    "object": {
        "type": "ITEM",
        "id": "DYGVVZKXC445CNLSEMO7GYI6",
        "updated_at": "2024-04-22T17:02:06.794Z",
        "created_at": "2024-04-22T16:54:15.539Z",
        "version": 1713805326794,
        "is_deleted": false,
        "present_at_all_locations": false,
        "present_at_location_ids": [
            "3Z4V4WHQK64X9"
        ],
        "absent_at_location_ids": [
            "FBVX8TZZTE11P",
            "T5Q6VBN7RC5P3"
        ],
        "item_data": {
            "name": "Not available in all locations",
            "is_taxable": true,
            "tax_ids": [
                "P2WTZJKP633HECJMGYHVWUU4",
                "FZ3MXFSXVJWINFZUJ2N3ND7J",
                "QZR25LKZ23SLVOPWFLJ4J3MS",
                "ZPTKVRGA2UDO2OZWL6ULID3H",
                "IQAZ4AX34FT4MEKQ4V6VC5LA"
            ],
            "variations": [
                {
                    "type": "ITEM_VARIATION",
                    "id": "7URWJFVADIYFMQEWYT7DWRAG",
                    "updated_at": "2024-04-22T17:02:06.794Z",
                    "created_at": "2024-04-22T16:54:15.539Z",
                    "version": 1713805326794,
                    "is_deleted": false,
                    "present_at_all_locations": false,
                    "present_at_location_ids": [
                        "3Z4V4WHQK64X9"
                    ],
                    "absent_at_location_ids": [
                        "FBVX8TZZTE11P",
                        "T5Q6VBN7RC5P3"
                    ],
                    "item_variation_data": {
                        "item_id": "DYGVVZKXC445CNLSEMO7GYI6",
                        "name": "Regular",
                        "sku": "F710027",
                        "ordinal": 1,
                        "pricing_type": "FIXED_PRICING",
                        "price_money": {
                            "amount": 200,
                            "currency": "USD"
                        },
                        "track_inventory": false,
                        "sellable": true,
                        "stockable": true,
                        "subscription_plan_ids": [
                            "TBIIVKRVWDZCR3GFT73HZDL2",
                            "J27BT5MGHLJRIJIWRAGIIXQO",
                            "AEZUVJGZ2HUJNT4WBXHBBQRZ",
                            "DA442EYC7ITK75BAJS4TIW7J",
                            "ATZTVO7BLE6AV37DJ7K3FRVZ"
                        ],
                        "default_unit_cost": {
                            "amount": 100,
                            "currency": "USD"
                        },
                        "channels": [
                            "CH_f9gD2j40pQDTgUvP1vYQRt7mcu1kOBoMsIie5PlQuYC"
                        ],
                        "item_variation_vendor_info_ids": [
                            "OGKYYFVBANSHAKNDTPB4CHZ2"
                        ],
                        "item_variation_vendor_infos": [
                            {
                                "type": "ITEM_VARIATION_VENDOR_INFO",
                                "id": "OGKYYFVBANSHAKNDTPB4CHZ2",
                                "updated_at": "2024-04-22T17:02:06.794Z",
                                "created_at": "2024-04-22T16:54:15.539Z",
                                "version": 1713805326794,
                                "is_deleted": false,
                                "present_at_all_locations": false,
                                "present_at_location_ids": [
                                    "3Z4V4WHQK64X9"
                                ],
                                "absent_at_location_ids": [
                                    "FBVX8TZZTE11P",
                                    "T5Q6VBN7RC5P3"
                                ],
                                "item_variation_vendor_info_data": {
                                    "ordinal": 1,
                                    "price_money": {
                                        "amount": 100,
                                        "currency": "USD"
                                    },
                                    "item_variation_id": "7URWJFVADIYFMQEWYT7DWRAG"
                                }
                            }
                        ]
                    }
                }
            ],
            "product_type": "REGULAR",
            "skip_modifier_screen": true,
            "channels": [
                "CH_f9gD2j40pQDTgUvP1vYQRt7mcu1kOBoMsIie5PlQuYC"
            ],
            "is_archived": false
        }
    }
}

:slightly_smiling_face:

Thank you for providing the sample API Request. Below is the API Request that I am sending to the BatchUpsertCatalogObjects endpoint of Catalog API.

After comparing your sample API Request with the API Request that I am sending, it looks like I am providing the required fields that the API needs. Could you help me spot my mistake in the API request below (used location Id and item Id from the sample above)?

{
  "idempotency_key": "450c87d8-f81a-4cdc-a582-3ce1baab6582",
  "batches": [
    {
      "objects": [
        {
          "type": "ITEM",
          "id": "DYGVVZKXC445CNLSEMO7GYI6",
          "present_at_all_locations": false,
          "absent_at_location_ids": [
            "T5Q6VBN7RC5P3"
          ],
          "present_at_location_ids": [
            "FBVX8TZZTE11P",
            "3Z4V4WHQK64X9"
          ],
          "version": 1713805326794,
          "item_data": {
            "name": "Not available in all locations",
            "description_html": "Not available in all locations",
            "categories": [
              {
                "id": "6THUX6BOFNWX7XFVWXT76898"
              }
            ],
            "variations": [
              {
                "type": "ITEM_VARIATION",
                "id": "7URWJFVADIYFMQEWYT7DWRAG",
                "present_at_all_locations": false,
                "absent_at_location_ids": [
                  "T5Q6VBN7RC5P3"
                ],
                "present_at_location_ids": [
                  "FBVX8TZZTE11P",
                  "3Z4V4WHQK64X9"
                ],
                "item_variation_data": {
                  "item_id": "DYGVVZKXC445CNLSEMO7GYI6",
                  "name": "Regular",
                  "sku": "F710027",
                  "pricing_type": "FIXED_PRICING",
                  "price_money": {
                      "amount": 200,
                      "currency": "USD"
                  },
                },
                "version": 1713805326794
              }
            ]
          }
        }
      ]
    }
  ]
}

Hello, could anyone please have a look at above?

What error are you getting when trying to upsert? The error will tell you what values are causing the problem. :slightly_smiling_face:

Thank you for your reply. I am getting the below error:

{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "[merchant_token=JGUN56R6DGRYW] Object `7URWJFVADIYFMQEWYT7DWRAG` of type ITEM_VARIATION is enabled at unit `3Z4V4WHQK64X9`, but the referenced object with token `DYGVVZKXC445CNLSEMO7GYI6` of type ITEM is not.",
      "field": "item_id"
    }
  ]
}

You’ll need to enable the item for that location as well as the variation. :slightly_smiling_face:

I think that’s what I am doing below:

Hello, could anyone help on the above?

Hello, could anyone please give an update on the above?

I modified your request for my location_ids and it worked as expected. For example:


  "idempotency_key": "{{$guid}}",
  "batches": [
    {
      "objects": [
        {
          "type": "ITEM",
          "id": "#ITEM_LEVEL",
          "present_at_all_locations": false,
          "absent_at_location_ids": [
            "{{location_id}}"
          ],
          "present_at_location_ids": [
            "{{location_id_2}}",
            "{{location_id_3}}"
          ],
          "item_data": {
            "name": "Not available in all locations",
            "description_html": "Not available in all locations",
            "variations": [
              {
                "type": "ITEM_VARIATION",
                "id": "#ITEM_VARIATION_LEVEL",
                "present_at_all_locations": false,
                "absent_at_location_ids": [
                  "{{location_id}}"
                ],
                "present_at_location_ids": [
                  "{{location_id_2}}",
                  "{{location_id_3}}"
                ],
                "item_variation_data": {
                  "item_id": "#ITEM_LEVEL",
                  "name": "Regular",
                  "sku": "F710027",
                  "pricing_type": "FIXED_PRICING",
                  "price_money": {
                      "amount": 200,
                      "currency": "USD"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

:slightly_smiling_face:

This post help me a lot, thanks everyone for sharing your knowledge..