Applies to: Catalog API
Learn how to build a simple product catalog for a cafe that serves coffee in small and large sizes, with skim or whole milk.
The Catalog API manages the item library in the Square Dashboard. Use it to add, update, or delete items. An item is made up of related catalog objects like taxes, modifiers, and options.
- You have a Square account enabled for payment processing. If you haven't enabled payment processing on your account (or you're not sure), visit squareup.com/activation.
- You're familiar with HTTPS. If this is your first time working with HTTPS, see TLS and HTTPS before continuing.
- You need a valid access token. You should test with Sandbox credentials whenever possible. For more information, see Access Tokens and Other Square Credentials.
The Catalog API includes several objects that enable efficient and standardized definitions of item variations in the seller's inventory. These objects include the following:
- Items - Generalized items such as "Shirt".
- Item variation - Specific items for sale such as "Polo shirt: Lg, red".
- Item options - Standardized attributes such as color, size, and style.
To add an item to a seller's library, use the UpsertCatalogObject endpoint to create catalog objects for the item (for example, a cup of coffee). For information about using item options to set variation characteristics, see Define Item Variations Using Options.
Before selling coffee, the catalog needs an item called "Cup of Coffee" without a size, a price, or modifiers. To charge for the coffee, include variations specifying the size, the price, and any modifiers. Add two variations (Small Coffee and Large Coffee), a CatalogTax object for taxes, and two optional CatalogModifier objects (with Skim Milk and Whole Milk). These include:
- A CatalogItem object named
Coffee
for coffee drinks. - Two CatalogItemVariation objects named
Small
andLarge
for the coffee drink size variations. - A CatalogTax object for the sales tax applied when a payment is made on the coffee drink order.
- Two CatalogModifier objects for the two milk choices.
- A CatalogModifierList object to hold the two CatalogModifier objects to apply the milk choices to the coffee item.
The following steps apply to creating other types of catalog objects, except for image uploads. For details about uploading and attaching images to items, variations, or categories, see Work with Images.
Important
When creating an item, you must specify at least one variation. Otherwise, you get an INVALID_REQUEST
error.
To add a coffee item to a catalog as a product offering of a seller, call the UpsertCatalogObject endpoint to create a CatalogItem object in the catalog. This is shown in the following REST API example:
Upsert catalog object
In this example, the Coffee
item has two variations (Small
and Large
).
#coffee
is a temporary ID used as a placeholder for the permanent ID generated by Square. In the same request, you can use this temporary ID to reference the new object. The two variations in this example use #coffee
to identify their parent item. If created in a separate request, use their Square-generated permanent IDs instead.
Because the UpsertCatalogObject
endpoint creates various catalog objects, the data object must match the specified type. For example:
- Item - Set the
item_data
property to a CatalogItem object for theITEM
type. - Item Variation - Set
item_variation_data
to a CatalogItemVariation object for theITEM_VARIATION
type. - Item Discount - Set
discount_data
to a CatalogDiscount object for aDISCOUNT
.
Warning
The type
property must match the {object_type}_data
property. Otherwise, the request fails.