Orders API

Retrieve Orders

Learn how to use the RetrieveOrder and BatchRetrieveOrders endpoints to retrieve one or more orders. For an order line item that is a catalog item, you learn how to use the Catalog API to access additional catalog attributes.

Retrieve one or more orders Permalink Get a link to this section

You can retrieve a single order or a set of orders using their IDs and the following endpoints. These endpoints return orders regardless of how or when they entered the Square ecosystem (Square Point of Sale, Invoices, or the Orders API).

  • Use the RetrieveOrder endpoint to retrieve an order. You only provide an order ID in the request. The endpoint returns the order regardless of the business location where the order was created.

    Retrieve Order
    • 1
    • 2
    • 3
    • 4
    curl https://connect.squareupsandbox.com/v2/orders/{order_id} \
      -H 'Square-Version: 2021-09-15' \
      -H 'Authorization: Bearer {ACCESS_TOKEN}' \
      -H 'Content-Type: application/json'
  • Use the BatchRetrieveOrders endpoint to retrieve a set of orders (within the scope of the current authorization's merchant ID). In the request, you provide a list of order IDs and an optional business location ID.

    • Location ID specified. The endpoint returns only the orders, in the specified list, that are associated with the location.

    • Location ID not specified. The endpoint returns all orders specified in the list.

    Batch Retrieve Orders
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    curl https://connect.squareupsandbox.com/v2/orders/batch-retrieve \
      -X POST \
      -H 'Square-Version: 2021-09-15' \
      -H 'Authorization: Bearer {ACCESS_TOKEN}' \
      -H 'Content-Type: application/json' \
      -d '{
        "location_id": "X9XWRESTK1CZ1",
        "order_ids": [
          "jGsodmQCXwftf8SSAFwJftMF",
          "xhUpgH9xst3vd1lL4PLS7sMF"
        ]
      }'

Retrieve catalog attributes of an order line item Permalink Get a link to this section

When you create an order, a line item in the order can be a catalog item or an ad hoc item (see Create line items . For a catalog item, the resulting Order object stores the catalog_object_id and catalog_version of the item. You can use this information to access other catalog attributes using the Catalog API (RetrieveCatalogObject endpoint).

For illustration, sku and category_name information of the line item are retrieved. These attributes are part of CatalogObject as follows:

  • sku is now part of a CatalogObject of type ITEM_VARIATION.

  • category_name now appears as the name field of the CatalogObject of type CATEGORY.

You can access these CatalogObjects using the RetrieveCatalogObject endpoint (Catalog API). The steps are:

  1. Make sure you have the catalog_object_id and catalog_version of the line item from your Order object.

  2. Call RetrieveCatalogObject by providing:

    • catalog_object_id as the object_id path parameter value

    • catalog_version as the query parameter value
      An example is shown. Note that if the catalog_version is not specified, the latest version is assumed.

    Retrieve Catalog Object
    • 1
    • 2
    • 3
    • 4
    curl https://connect.squareupsandbox.com/v2/catalog/object/{object_id}?catalog_version=catalog_version \
      -H 'Square-Version: 2021-09-15' \
      -H 'Authorization: Bearer ACCESS_TOKEN' \
      -H 'Content-Type: application/json'

    In response, you get a catalog object of the ITEM type. The following is an example response. The item_variation_data provides the sku.

    {
      "object": {
        "type": "ITEM",
        "id": "WWCAXYB6EEA5WT4PYXREV262",
         ...
        "item_data": {
          "name": "Hamburger",
    
          "category_id": "WBV5YL4R3DCHXVDFDQ22KPVU",
          "variations": [
            {
              "type": "ITEM_VARIATION",
              "id": "RA43EL3Z3JWI52PCD4DPCV7B",
              ...
              "item_variation_data": {
                "item_id": "WWCAXYB6EEA5WT4PYXREV262",
                "name": "Regular",
                "sku": "burgerSKU1",
                 "price_money": {
                  "amount": 500,
                  "currency": "USD"
                },
              }
            }
          ],
          ...
        }
      }
    }
    

    Note that the catalog object in the response also provides the category_id of the object. You can use it to access the category name of the line item in the next RetrieveCatalogObject call.

  3. Call RetrieveCatalogObject by providing:

    • category_id as the object_id path parameter value (a category is also a catalog object. Therefore, you specify the category ID as the ID of the catalog object to retrieve).

    • catalog_version as the query parameter value;
      An example is shown.

    Retrieve Catalog Object
    • 1
    • 2
    • 3
    • 4
    curl https://connect.squareupsandbox.com/v2/catalog/object/{object_id}?catalog_version=catalog_version \
      -H 'Square-Version: 2021-09-15' \
      -H 'Authorization: Bearer ACCESS_TOKEN' \
      -H 'Content-Type: application/json'

    In response, you get a catalog object of the CATEGORY type. The following is an example response. The category_data provides the name of the category (of your line item in the order).

    {
       "object": {
        "type": "CATEGORY",
        "id": "WBV5YL4R3DCHXVDFDQ22KPVU",
        "updated_at": "2021-07-12T19:02:57.355Z",
        "version": 1626116577355,
        "is_deleted": false,
        "present_at_all_locations": true,
        "category_data": {
          "name": "Burgers"
        }
      }
    }
    

Related topics Permalink Get a link to this section