Applies to: Merchant Custom Attributes API
Learn how to define merchant-related custom attributes for Square sellers using the Merchant Custom Attributes API.
A custom attribute definition specifies the key
identifier, the visibility
setting, the schema
data type, and other properties for a custom attribute. After the definition is created, an associated custom attribute can be created and assigned to a merchant. For more information about how merchant-related custom attributes work, see Custom Attributes for Merchants.
A custom attribute definition is represented by a CustomAttributeDefinition
object. The following is an example custom attribute definition that defines a "charity" custom attribute of the Boolean
data type:
{
"custom_attribute_definition": {
"key": "charity",
"name": "Charitable Organization",
"description": "Is this merchant a charitable organization with 501(c)(3) status?",
"version": 1,
"updated_at": "2023-01-20T02:41:37Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.Boolean"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_READ_WRITE_VALUES"
}
}
The following fields represent core properties of a custom attribute definition:
Field | Description |
---|---|
key | The identifier for the definition and its corresponding custom attributes. This key value is unique for the application and cannot be changed after the definition is created.The field can contain up to 60 alphanumeric characters, periods ( . ), underscores (_ ), and hyphens (- ) and must match the following regular expression: ^[a-zA-Z0-9\._-]{1,60}$ . |
name | The name for the custom attribute. This field is required unless the visibility field is set to VISIBILITY_HIDDEN . |
description | The description for the custom attribute. This field is required unless the visibility field is set to VISIBILITY_HIDDEN . |
visibility | The access control setting that determines whether other applications (including Square products such as the Square Dashboard) can view the definition and view or edit corresponding custom attributes. Valid values are VISIBILITY_HIDDEN , VISIBILITY_READ_ONLY , and VISIBILITY_READ_WRITE_VALUES . |
schema | The data type of the custom attribute value. For more information, see Supported data types. The total schema size cannot exceed 12 KB. |
version | The version number of the custom attribute definition. The version number is initially set to 1 and incremented each time the definition is updated. Include this field in update operations to enable optimistic concurrency control and in read operations for strong consistency. |
Use the CreateMerchantCustomAttributeDefinition endpoint to create a custom attribute definition for a seller account. This operation makes the custom attribute available to that merchant.
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 following is an example response:
{
"custom_attribute_definition": {
"key": "business-owner",
"name": "Business Owner",
"description": "The name of the business owner",
"version": 1,
"updated_at": "2023-01-20T02:41:37Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_READ_WRITE_VALUES"
}
}
Now that the custom attribute definition is created, you can set the custom attribute for the merchant individually or in bulk.
After a custom attribute definition is created, Square invokes the merchant.custom_attribute_definition.owned.created
and merchant.custom_attribute_definition.visible.created
webhooks.
A seller account can have a maximum of 100 merchant-related custom attribute definitions per application.
For a Selection
data type, the schema contains a $schema
field that references a JSON meta-schema object, as well as additional fields. Note the following:
$schema
references thehttps://developer-production-s.squarecdn.com/meta-schemas/v1/selection.json meta-schema
hosted on the Square CDN.type
must bearray
.items
must include anames
array that contains strings representing the display names of the predefined options that can be selected. Note that the order of the options might not be respected by all UIs.maxItems
is an integer that represents the maximum number of allowed selections. Corresponding custom attributes can have zero or more selected values, up to the specified maximum. The minimum value is 1 and cannot exceed the number of options in thenames
field.uniqueItems
must betrue
.
The following example request creates a Selection
-type custom attribute definition that contains six named options and allows for a selection of all six:
Create merchant custom attribute definition
The following is an example response. For each named option, Square generates a UUID and adds it to the enum
field. The options in the names
field map by index to the UUIDs in the enum
field. The first option maps to the first UUID, the second option maps to the second UUID, and so on.
These UUIDs are used to set the value of the custom attribute or update the option names.
{
"custom_attribute_definition": {
"key": "diversity-label",
"name": "Diversity label",
"description": "The self-reported diversity label(s) for the business",
"version": 1,
"updated_at": "2022-12-06T15:57:23.211Z",
"schema": {
"$schema": "https://developer-production-s.squarecdn.com/meta-schemas/v1/selection.json",
"maxItems": 3.0,
"type": "array",
"uniqueItems": true,
"items": {
"names": [
"Woman-owned",
"Black-owned",
"Asian-owned",
"Indigenous-owned",
"LGBTQ+ owned",
"Veteran-owned"
],
"enum": [
"46efa55a-1f1d-467f-9733-468f881a4f20",
"954998e1-b666-43a4-baf3-89cb87afe25a",
"610fa590-70cd-4ec9-b64c-1dad6ba3c8f9",
"92ds8kzp-44tz-38d7-vjsg-rj35apkvg5vt",
"2jrxqv8l-9pcn-adfg-g35u-65yi30ref2od",
"b2f3cfed-c884-4621-9a16-c24932480c24"
]
}
},
"created_at": "2022-12-06T15:57:23.211Z",
"visibility": "VISIBILITY_READ_ONLY"
}
}
Use the UpdateMerchantCustomAttributeDefinition endpoint to update a custom attribute definition for a seller account. The endpoint supports sparse updates, so only new or changed fields need to be included in the request. Only the following fields can be updated:
name
description
visibility
schema
for aSelection
data type
Note the following about an UpdateMerchantCustomAttributeDefinition
request:
- A custom attribute definition can only be updated by the definition owner.
- The
key
path parameter is thekey
of the custom attribute definition. - The
version
field must match the current version of the custom attribute definition to enable optimistic concurrency control. If this isn't important for your application,version
can be set to –1. For any other values, the request fails with aBAD_REQUEST
error. Square increments the version number each time the definition is updated. - The
idempotency_key
is a unique ID for the request that can be optionally included to ensure idempotency. - Changes to the
visibility
setting are propagated to corresponding custom attributes within a few seconds. At that time, theupdated_at
andversion
fields of the custom attributes are also updated. ForVISIBILITY_READ_ONLY
orVISIBILITY_READ_WRITE_VALUES
settings, the definition must have both aname
and adescription
.
The following request updates the visibility
setting of a definition:
Update merchant custom attribute definition
The following is an example response:
{
"custom_attribute_definition": {
"key": "business-owner",
"name": "Business Owner",
"description": "The name of the business owner",
"version": 2,
"updated_at": "2023-02-02T04:17:09Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_READ_ONLY"
}
}
After a merchant-related custom attribute definition is updated, Square invokes the merchant.custom_attribute_definition.owned.updated
and merchant.custom_attribute_definition.visible.updated
webhooks.
For a Selection
data type, you can update the maximum number of allowed selections and the set of predefined named options.
Note
Square validates custom attribute selections on upsert operations, so these changes apply only for future upsert operations. They don't affect custom attributes that have already been set on a merchant.
The information you send in the UpdateMerchantCustomAttributeDefinition request depends on the change you want to make:
- To change the maximum number of allowed selections, include the
maxItems
field with the new integer value. The minimum value is 1 and cannot exceed the number of options in thenames
field. - To change the set of predefined named options, include the
items
field with the completenames
andenum
arrays. The options in thenames
array map by index to the Square-assigned UUIDs in theenum
array, which are unique per seller. The first option maps to the first UUID, the second option maps to the second UUID, and so on.- To add an option:
- Add the name of the new option at the end of the
names
array. New options must always be added to the end of the array. - Don't change the
enum
array. Square generates a UUID for the new option and adds it to the end of the enum array.
- Add the name of the new option at the end of the
- To reorder the options:
Change the order of the names in the
names
array.Change the order of the UUIDs in the
enum
array so that the order of the UUIDs matches the order of the corresponding named options.Note that the order might not be respected by all UIs.
- To remove an option:
- Remove the name of the option from the
names
array. - Remove the corresponding UUID from the
enum
array.
- Remove the name of the option from the
- To add an option:
The following UpdateMerchantCustomAttributeDefinition
request adds two new options by adding their names at the end of the names
array:
Update merchant custom attribute definition
The following example response includes the UUIDs that Square generated for the new Furniture consignment
and Rug cleaning
options:
{
"custom_attribute_definition": {
"key": "diversity-label",
"name": "Diversity label",
"description": "The self-reported diversity label(s) for the business",
"version": 2,
"updated_at": "2023-01-09T15:57:23.211Z",
"schema": {
"$schema": "https://developer-production-s.squarecdn.com/meta-schemas/v1/selection.json",
"maxItems": 8.0,
"type": "array",
"uniqueItems": true,
"items": {
"names": [
"Woman-owned",
"Black-owned",
"Asian-owned",
"Indigenous-owned",
"LGBTQ+ owned",
"Veteran-owned",
"Latin-owned",
"Pacific Islander-owned"
],
"enum": [
"46efa55a-1f1d-467f-9733-468f881a4f20",
"954998e1-b666-43a4-baf3-89cb87afe25a",
"610fa590-70cd-4ec9-b64c-1dad6ba3c8f9",
"92ds8kzp-44tz-38d7-vjsg-rj35apkvg5vt",
"2jrxqv8l-9pcn-adfg-g35u-65yi30ref2od",
"b2f3cfed-c884-4621-9a16-c24932480c24",
"6etk4juf-q3px-44jm-b7zp-vpwkv89dsok2",
"46y4hveq-s4c5-7zvt-cyrb-2ferha95fvlv"
]
}
},
"created_at": "2022-12-06T15:57:23.211Z",
"visibility": "VISIBILITY_READ_ONLY"
}
}
Use the ListMerchantCustomAttributeDefinitions endpoint to list the custom attribute definitions from a seller account.
The limit query parameter optionally specifies a maximum page size of 100 results. The default limit is 20 results. If the results are paged, the cursor
field in the response contains a value that you can send with the cursor
query parameter to retrieve the next page of results.
The following example request includes the limit query parameter:
List merchant custom attribute definitions
When all pages are retrieved, all custom attribute definitions created by the requesting application are included in the results. The key
for these definitions is the key
value that was provided when the definition was created.
Custom attribute definitions created by other applications are included if their visibility
setting is VISIBILITY_READ_ONLY
or VISIBILITY_READ_WRITE_VALUES
.
The following is an example response containing four custom attribute definitions:
{
"custom_attribute_definitions": [
{
"key": "business-owner",
"name": "Business Owner",
"description": "The name of the business owner",
"version": 2,
"updated_at": "2023-02-02T04:17:09Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_READ_ONLY"
},
{
"key": "owner-email",
"name": "Business Owner Email",
"description": "The email address of the business owner",
"version": 1,
"updated_at": "2023-01-20T02:41:37Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.Email"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_HIDDEN"
},
{
"key": "employees",
"name": "Number of employees",
"description": "The number of full-time employees of this merchant",
"version": 1,
"updated_at": "2022-12-02T19:51:29.235Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.Number"
},
"created_at": "2022-12-02T19:51:29.235Z",
"visibility": "VISIBILITY_READ_WRITE_VALUES"
},
{
"key": "diversity-label",
"name": "Diversity label",
"description": "The self-reported diversity label(s) for the business",
"version": 2,
"updated_at": "2022-12-06T15:57:23.211Z",
"schema": {
"$schema": "https://developer-production-s.squarecdn.com/meta-schemas/v1/selection.json",
"maxItems": 8.0,
"type": "array",
"uniqueItems": true,
"items": {
"names": [
"Woman-owned",
"Black-owned",
"Asian-owned",
"Indigenous-owned",
"LGBTQ+ owned",
"Veteran-owned",
"Latin-owned",
"Pacific Islander-owned"
],
"enum": [
"46efa55a-1f1d-467f-9733-468f881a4f20",
"954998e1-b666-43a4-baf3-89cb87afe25a",
"610fa590-70cd-4ec9-b64c-1dad6ba3c8f9",
"92ds8kzp-44tz-38d7-vjsg-rj35apkvg5vt",
"2jrxqv8l-9pcn-adfg-g35u-65yi30ref2od",
"b2f3cfed-c884-4621-9a16-c24932480c24",
"6etk4juf-q3px-44jm-b7zp-vpwkv89dsok2",
"46y4hveq-s4c5-7zvt-cyrb-2ferha95fvlv"
]
}
},
"created_at": "2022-12-06T15:57:23.211Z",
"visibility": "VISIBILITY_READ_ONLY"
}
]
}
Note that the "Business Owner"
and "Business Owner email"
custom attribute definitions were created by the requesting application. Because "Business Owner email"
is set to VISIBILITY_HIDDEN
, it is returned only when requested by the definition owner.
If no custom attribute definitions are found, Square returns an empty response.
{}
Use the RetrieveMerchantCustomAttributeDefinition endpoint to retrieve a custom attribute definition using its key
. Note the following:
- The
key
path parameter is thekey
value of the custom attribute definition. - The
version
query parameter is used for strongly consistent reads to guarantee that you receive the most up-to-date data. When included in the request, Square returns the specified version or a later version if one exists. If the specified version is later than the current version, Square returns a400 BAD_REQUEST
error.
The following is an example request:
Retrieve merchant custom attribute definition
Note
Square also returns custom attribute definitions for RetrieveMerchantCustomAttribute
or ListMerchantCustomAttributes
requests if you set the with_definition
or with_definitions
query parameter to true
. For more information, see Retrieve a merchant custom attribute or List merchant custom attributes.
The following is an example response:
{
"custom_attribute_definition": {
"key": "business-owner",
"name": "Business Owner",
"description": "The name of the business owner",
"version": 2,
"updated_at": "2023-02-02T04:17:09Z",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String"
},
"created_at": "2023-01-20T02:41:37Z",
"visibility": "VISIBILITY_READ_ONLY"
}
}
If the custom attribute definition isn't found, Square returns an errors
field that contains a 404 NOT_FOUND
error.
Use the DeleteMerchantCustomAttributeDefinition endpoint to delete a custom attribute definition from a seller account. Note the following:
- Only the definition owner can delete a custom attribute definition.
- The
key
path parameter is thekey
value of the custom attribute definition. - Deleting a custom attribute definition also deletes the corresponding custom attribute from all merchants on which it has been set.
The following is an example request:
Delete merchant custom attribute definition
If successful, Square returns an empty object.
{}
After a custom attribute definition is deleted, Square invokes the merchant.custom_attribute_definition.owned.deleted
and merchant.custom_attribute_definition.visible.deleted
webhooks.