Custom attributes
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:
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
Using the Merchant Custom Attributes API consists of the following workflow:
- Create a custom attribute definition for a merchant (Square seller).
- Assign a custom attribute value to a merchant.
- Retrieve custom attributes from merchants.
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
After the custom attribute definition is created, you create new custom attributes and assign them to specific sellers (merchants). The following UpsertMerchantCustomAttributemerchant_id
and key
. Note the following:
- The
key
in the path isbusiness-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 typedata type specified by theschema
field in the definition. In this case, it's aString
.
Upsert merchant custom attribute
Note
Square also provides the BulkUpsertMerchantCustomAttributes
You can now retrieve the custom attribute to get the value that was set for the merchant.
The following RetrieveMerchantCustomAttributemerchant_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.
The Merchant Custom Attributes API supports the following operations:
- Create a merchant custom attribute definition
Create a merchant custom attribute definition - Update a merchant custom attribute definition
Update a merchant custom attribute definition - List merchant custom attribute definitions
List merchant custom attribute definitions - Retrieve a merchant custom attribute definition
Retrieve a merchant custom attribute definition - Delete a merchant custom attribute definition
Delete a merchant custom attribute definition
- Create or update a merchant custom attribute
Create or update a merchant custom attribute - Bulk create or update merchant custom attributes
Bulk create or update merchant custom attributes - List merchant custom attributes
List merchant custom attributes - Retrieve a merchant custom attribute
Retrieve a merchant custom attribute - Delete a merchant custom attribute
Delete a merchant custom attribute - Bulk delete merchant custom attributes
Bulk delete merchant custom attributes
Each custom attribute definition is scoped to a specific seller. Some Square APIs that use custom attributes (for example CustomersMerchant
object, merchant custom attributes and their definitions cannot be shared between merchants.
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 isVISIBILITY_READ_ONLY
orVISIBILITY_READ_WRITE_VALUES
.
Notification payloads for both options contain the same information.
Subscribe to the following events to receive notifications for changes to custom attribute definitions and custom attributes that are owned by your application:
Event | Permission | Description |
---|---|---|
merchant.custom_attribute_definition.owned.created | MERCHANT_PROFILE_READ | A 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.updated | MERCHANT_PROFILE_READ | A 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.deleted | MERCHANT_PROFILE_READ | A 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.updated | MERCHANT_PROFILE_READ | A custom attribute owned by your application was created or updated for a merchant. |
merchant.custom_attribute.owned.deleted | MERCHANT_PROFILE_READ | A 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.
Event | Permission | Description |
---|---|---|
merchant.custom_attribute_definition.visible.created | MERCHANT_PROFILE_READ | A custom attribute definition that's visible to your application was created. |
merchant.custom_attribute_definition.visible.updated | MERCHANT_PROFILE_READ | A custom attribute definition that's visible to your application was updated. |
merchant.custom_attribute_definition.visible.deleted | MERCHANT_PROFILE_READ | A custom attribute definition that's visible to your application was deleted. |
merchant.custom_attribute.visible.updated | MERCHANT_PROFILE_READ | A custom attribute that's visible to your application was created or updated for a merchant. |
merchant.custom_attribute.visible.deleted | MERCHANT_PROFILE_READ | A 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:
{ "merchant_id": "DM7VKY8Q63GNP", "type": "merchant.custom_attribute_definition.visible.created", "event_id": "347ab320-c0ba-48f5-959a-4e147b9aefcf", "created_at": "2023-01-20T02:41:37Z", "data": { "type": "custom_attribute_definition", "id": "business-owner", "object": { "created_at": "2023-01-20T02:41:37Z", "description": "The name of the business owner", "key": "business-owner", "name": "Business Owner", "schema": { "$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String" }, "updated_at": "2023-01-20T02:41:37Z", "version": 1, "visibility": "VISIBILITY_READ_WRITE_VALUES" } } }
The following is an example merchants.custom_attribute.visible.updated
notification:
{ "merchant_id": "DM7VKY8Q63GNP", "type": "merchants.custom_attribute.visible.updated", "event_id": "1cc2925c-f6e2-4fb6-a597-07c198de59e1", "created_at": "2023-03-15T08:00:00Z", "data": { "type": "custom_attribute", "id": "business-owner", "object": { "created_at": "2023-01-20T02:41:37Z", "key": "business-owner", "updated_at": "2023-03-15T08:00:00Z", "value": "Christine Lee", "version": 2, "visibility": "VISIBILITY_READ_WRITE_VALUES" } } }
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