Can I get an item from an order that has already been deleted from the Catalog?

I’m trying to find orders that contain a specific Item that has been deleted from the Catalog. I can find the Item in the Catalog using the SearchCatalogObjects API and searching for the specific ‘name’ but I don’t see any other way to locate that previously deleted Item.
The other issue is that the Item in the Order is actually the Item Variation ID and not the “root” Item. If you look at the data returned from the SearchCatalogObjects for the delted Item it does not return the Variation information. Because of that I can’t even to a broader search using SearchCatalogObjects and then cycle through the data myself since the Variation is not included in the returned data.
I have not found that the Order contains the “root” Item ID unless I’m just missing it.

Thanks!
vhovar

:wave: With Square if you’d like to get the specific version of a deleted object from orders that are completed you can use BatchRetrieveCatalogObjects with the following:

{
    "object_ids": [
      "{{catalog_object_id}}"
    ],
    "catalog_version": "{{catalog_version}}",
    "include_deleted_objects": true
  }

:slightly_smiling_face:

Hey thanks Brian but is there a reason this would not work with the API Explorer? Here is what I tried and get in return:

curl https://connect.squareup.com/v2/catalog/batch-retrieve \
  -X POST \
  -H 'Square-Version: 2022-02-16' \
  -H 'Authorization: Bearer ??????? \
  -H 'Content-Type: application/json' \
  -d '{
    "object_ids": [
      "642H3DA7OUHG3WFGYUKNPML2"
    ],
    "catalog_version": 1644933420825,
    "include_related_objects": true
  }'

200 Response
cache-control: max-age=0, private, must-revalidate
content-length: 2
content-type: application/json
date: Fri, 18 Feb 2022 21:31:17 GMT
square-version: 2022-02-16

{}

Here is my Item that I’m trying to locate that I was able to retrieve using SearchCatalogObjects:

curl https://connect.squareup.com/v2/catalog/search \
  -X POST \
  -H 'Square-Version: 2022-02-16' \
  -H 'Authorization: Bearer ????????? \
  -H 'Content-Type: application/json' \
  -d '{
    "include_deleted_objects": true,
    "include_related_objects": true,
    "object_types": [
      "ITEM"
    ],
    "query": {
      "exact_query": {
        "attribute_name": "name",
        "attribute_value": "Cinnamon Roll-GF &  DF"
      }
    }
  }'

200 Response
cache-control: max-age=0, private, must-revalidate
content-encoding: gzip
content-type: application/json
date: Fri, 18 Feb 2022 21:38:49 GMT
square-version: 2022-02-16

{
  "objects": [
    {
      "type": "ITEM",
      "id": "642H3DA7OUHG3WFGYUKNPML2",
      "updated_at": "2022-02-15T13:57:00.825Z",
      "created_at": "2022-01-31T17:56:43.335Z",
      "version": 1644933420825,
      "is_deleted": true,
      "present_at_all_locations": false,
      "present_at_location_ids": [
        "3CB1PY9VJHZ8X"
      ],
      "item_data": {
        "name": "Cinnamon Roll-GF &  DF",
        "description": "**INTRO PRICE!** These gluten free and dairy free rolls are just as tasty for those craving a traditional cinnamon roll!<br />They are not made with nut flour, but they do contain coconut milk. They also contain soy and eggs.",
        "abbreviation": "GF CR",
        "label_color": "E5BF00",
        "visibility": "PRIVATE",
        "available_online": false,
        "available_for_pickup": false,
        "available_electronically": false,
        "category_id": "WPLQ4GJRYZ3ZY5ISWI2XHS5O",
        "ordinal": 0,
        "product_type": "REGULAR",
        "skip_modifier_screen": false,
        "ecom_uri": "https://fusionbrew.square.site/product/cinnamon-roll-gf-df/322",
        "ecom_image_uris": [
          "https://fusionbrew.square.site/uploads/1/2/6/1/126108013/s134838118258639312_p322_i1_w1949.jpeg"
        ],
        "ecom_available": false,
        "ecom_visibility": "UNAVAILABLE",
        "image_ids": [
          "4CWCLXNMB7PZY72VDT3TGTA4"
        ]
      }
    }
  ],
  "related_objects": [
    {
      "type": "CATEGORY",
      "id": "WPLQ4GJRYZ3ZY5ISWI2XHS5O",
      "updated_at": "2019-04-05T22:59:12.406Z",
      "created_at": "2019-03-27T13:23:47.192Z",
      "version": 1554505152406,
      "is_deleted": false,
      "present_at_all_locations": true,
      "category_data": {
        "name": "PASTRY",
        "abbreviation": "Pstry",
        "label_color": "ffe5bf00"
      }
    },
    {
      "type": "IMAGE",
      "id": "4CWCLXNMB7PZY72VDT3TGTA4",
      "updated_at": "2022-02-11T12:00:46.51Z",
      "created_at": "2022-02-11T12:00:46.51Z",
      "version": 1644580846510,
      "is_deleted": false,
      "present_at_all_locations": true,
      "image_data": {
        "name": "GF Cinnamon Roll.jpg",
        "url": "https://items-images-production.s3.us-west-2.amazonaws.com/files/1d00645070dc12225efc627ca315193b0e9c21ec/original.jpeg"
      }
    }
  ],
  "latest_time": "2022-02-18T21:29:39.558Z"
}

Am I missing something?

Also, it appears that there isn’t a related Variation which is what the order will have for a catalog_object_id. I’d try to run the query using the Item Variation id but I don’t know what it is since my task is to try and locate an order that has that deleted Item Variation on it.

Thanks,

Currently it won’t work in the API Explorer since you aren’t able to set "include_deleted_objects": true. You have include_related_objects in your request. It hasn’t yet been made available with the API Explorer but if you run the following in terminal it will work:

curl https://connect.squareup.com/v2/catalog/batch-retrieve \
  -X POST \
  -H 'Square-Version: 2022-02-16' \
  -H 'Authorization: Bearer ??????? \
  -H 'Content-Type: application/json' \
  -d '{
    "object_ids": [
      "642H3DA7OUHG3WFGYUKNPML2"
    ],
    "catalog_version": 1644933420825,
    "include_deleted_objects": true
  }'

Great! I was able to get the BatchRetrieveCatalogObjects to work and retrieve the delete Item. It would be nice if the “include_deleted_objects” would also cascade along with the “include_related_objects” so the deleted variations were also returned.

Thank you again!

We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face: