Custom Attributes for Merchants

Custom attributes store additional properties or metadata about certain objects in the Square data model, allowing you to extend the functionality of your applications. Use the Merchant Custom Attributes API to extend the data model and associate seller-specific or application-specific information with merchants using your application. For example, you might want to store information such as the number of locations a merchant has, the business owner's name, or an email address.

A custom attribute obtains a key identifier, the visibility setting, allowed data types, and other properties from a custom attribute definition. This relationship is shown in the following diagram:

A diagram showing a custom attribute definition for “business owner“ used by custom attributes on multiple merchants.

Note

Working with custom attributes is different than working with native attributes on the Merchant object (such as business_name or currency) that are accessed using the Merchants API. For example, custom attributes aren't returned in a RetrieveMerchant, ListMerchants, or ListMerchants response.

Link to section

Basic workflow

Using the Merchant Custom Attributes API consists of the following workflow:

  1. Create a custom attribute definition for a merchant (Square seller).
  2. Assign a custom attribute value to a merchant.
  3. Retrieve custom attributes from merchants.
Link to section

Create a custom attribute definition

To create a merchant-related custom attribute, you must first define its properties by calling CreateMerchantCustomAttributeDefinition.

The following request creates a custom attribute definition to represent the name of a merchant's business owner. The schema field indicates that the value of the custom attribute is a String.

Create merchant custom attribute definition

The key identifier and visibility setting specified in the definition are used by the corresponding custom attributes. The visibility setting determines the access level that other applications (including other Square products) have to the definition and corresponding custom attributes.

Link to section

Assign custom attributes to merchants

After the custom attribute definition is created, you create new custom attributes and assign them to specific sellers (merchants). The following UpsertMerchantCustomAttribute request sets the Business Owner custom attribute using the merchant_id and key. Note the following:

  • The key in the path is business-owner, which is the same as the key specified by the definition.
  • The value in the request body sets the custom attribute value for the merchant. This value must conform to the data type specified by the schema field in the definition. In this case, it's a String.

Upsert merchant custom attribute

Note

Square also provides the BulkUpsertMerchantCustomAttributes endpoint to update multiple custom attributes for merchants in a single request.

Link to section

Retrieve custom attributes from merchants

You can now retrieve the custom attribute to get the value that was set for the merchant.

The following RetrieveMerchantCustomAttribute request retrieves the Business Owner custom attribute for a merchant using the merchant_id and key in the request path:

Retrieve merchant custom attribute

The following is an example response:

{ "custom_attribute": { "key": "business-owner", "version": 1, "updated_at": "2023-04-10T21:13:48Z", "value": "Adam Cortez", "created_at": "2023-04-10T21:13:48Z", "visibility": "VISIBILITY_READ_WRITE_VALUES" } }

You can optionally include the with_definition query parameter to return the corresponding custom attribute definition in the same call. For example, you might want to retrieve the definition to get the custom attribute's data type, name, or description.

Link to section

Supported operations

The Merchant Custom Attributes API supports the following operations:

Link to section

Working with merchant-related custom attribute definitions

Link to section

Working with merchant-related custom attributes

Link to section

Seller scope

Each custom attribute definition is scoped to a specific seller. Some Square APIs that use custom attributes (for example Customers or Bookings) allow you to make custom attributes available to multiple sellers that connect to your application with OAuth. However, because each Square seller is represented by a Merchant object, merchant custom attributes and their definitions cannot be shared between merchants.

Link to section

Webhooks

You can subscribe to receive notifications for merchant-related custom attribute events. Each event provides two options that allow you to choose when Square sends notifications:

  • .owned event notifications are sent when changes are made to custom attribute definitions and custom attributes that are owned by your application. A custom attribute definition is owned by the application that created it. A custom attribute is owned by the application that created the corresponding custom attribute definition.
  • .visible event notifications are sent when changes are made to custom attribute definitions and custom attributes that are visible to your application. These changes apply to:
    • All custom attribute definitions and custom attributes owned by your application.
    • All other custom attribute definitions or custom attributes whose visibility setting is VISIBILITY_READ_ONLY or VISIBILITY_READ_WRITE_VALUES.

Notification payloads for both options contain the same information.

Link to section

Webhook events

Subscribe to the following events to receive notifications for changes to custom attribute definitions and custom attributes that are owned by your application:

EventPermissionDescription
merchant.custom_attribute_definition.owned.createdMERCHANT_PROFILE_READA custom attribute definition was created by your application. The application that created the custom attribute definition is the owner of the definition and corresponding custom attributes.
merchant.custom_attribute_definition.owned.updatedMERCHANT_PROFILE_READA custom attribute definition owned by your application was updated. Note that only the definition owner can update a custom attribute definition.
merchant.custom_attribute_definition.owned.deletedMERCHANT_PROFILE_READA custom attribute definition owned by your application was deleted. Note that only the definition owner can delete a custom attribute definition.
merchant.custom_attribute.owned.updatedMERCHANT_PROFILE_READA custom attribute owned by your application was created or updated for a merchant.
merchant.custom_attribute.owned.deletedMERCHANT_PROFILE_READA custom attribute owned by your application was deleted from a merchant.

Subscribe to the following events to receive notifications for changes to custom attribute definitions and custom attributes that are visible to your application. These .visible events include changes to all custom attribute definitions and custom attributes that are owned by your application. Therefore, you don't need to subscribe to an .owned event when you subscribe to the corresponding .visible event.

EventPermissionDescription
merchant.custom_attribute_definition.visible.createdMERCHANT_PROFILE_READA custom attribute definition that's visible to your application was created.
merchant.custom_attribute_definition.visible.updatedMERCHANT_PROFILE_READA custom attribute definition that's visible to your application was updated.
merchant.custom_attribute_definition.visible.deletedMERCHANT_PROFILE_READA custom attribute definition that's visible to your application was deleted.
merchant.custom_attribute.visible.updatedMERCHANT_PROFILE_READA custom attribute that's visible to your application was created or updated for a merchant.
merchant.custom_attribute.visible.deletedMERCHANT_PROFILE_READA custom attribute that's visible to your application was deleted from a merchant.

Note

Upserting or deleting a custom attribute for a merchant doesn't invoke a merchant.updated webhook.

The following is an example merchant.custom_attribute_definition.visible.created notification:

The following is an example merchants.custom_attribute.visible.updated notification:

Note

Custom attributes are a feature shared by multiple Square APIs. For general information common to all Square APIs that support custom attributes, see Custom Attributes Overview.

Link to section

See also