$customerCustomAttributesApi = $client->getCustomerCustomAttributesApi();
CustomerCustomAttributesApi
- List Customer Custom Attribute Definitions
- Create Customer Custom Attribute Definition
- Delete Customer Custom Attribute Definition
- Retrieve Customer Custom Attribute Definition
- Update Customer Custom Attribute Definition
- Bulk Upsert Customer Custom Attributes
- List Customer Custom Attributes
- Delete Customer Custom Attribute
- Retrieve Customer Custom Attribute
- Upsert Customer Custom Attribute
Lists the customer-related custom attribute definitions that belong to a Square seller account.
When all response pages are retrieved, the results include all custom attribute definitions
that are visible to the requesting application, including those that are created by other
applications and set to VISIBILITY_READ_ONLY
or VISIBILITY_READ_WRITE_VALUES
. Note that
seller-defined custom attributes (also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function listCustomerCustomAttributeDefinitions(?int $limit = null, ?string $cursor = null): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
limit |
?int |
Query, Optional | The maximum number of results to return in a single paged response. This limit is advisory. The response might contain more or fewer results. The minimum value is 1 and the maximum value is 100. The default value is 20. For more information, see Pagination. |
cursor |
?string |
Query, Optional | The cursor returned in the paged response from the previous call to this endpoint. Provide this cursor to retrieve the next page of results for your original request. For more information, see Pagination. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type ListCustomerCustomAttributeDefinitionsResponse
.
$apiResponse = $customerCustomAttributesApi->listCustomerCustomAttributeDefinitions();
if ($apiResponse->isSuccess()) {
$listCustomerCustomAttributeDefinitionsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Creates a customer-related custom attribute definition for a Square seller account. Use this endpoint to define a custom attribute that can be associated with customer profiles.
A custom attribute definition specifies the key
, visibility
, schema
, and other properties
for a custom attribute. After the definition is created, you can call
UpsertCustomerCustomAttribute or
BulkUpsertCustomerCustomAttributes
to set the custom attribute for customer profiles in the seller's Customer Directory.
Sellers can view all custom attributes in exported customer data, including those set to
VISIBILITY_HIDDEN
.
function createCustomerCustomAttributeDefinition(
CreateCustomerCustomAttributeDefinitionRequest $body
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateCustomerCustomAttributeDefinitionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type CreateCustomerCustomAttributeDefinitionResponse
.
$body = CreateCustomerCustomAttributeDefinitionRequestBuilder::init(
CustomAttributeDefinitionBuilder::init()
->key('favoritemovie')
->name('Favorite Movie')
->description('The favorite movie of the customer.')
->visibility(CustomAttributeDefinitionVisibility::VISIBILITY_HIDDEN)
->build()
)->build();
$apiResponse = $customerCustomAttributesApi->createCustomerCustomAttributeDefinition($body);
if ($apiResponse->isSuccess()) {
$createCustomerCustomAttributeDefinitionResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Deletes a customer-related custom attribute definition from a Square seller account.
Deleting a custom attribute definition also deletes the corresponding custom attribute from all customer profiles in the seller's Customer Directory.
Only the definition owner can delete a custom attribute definition.
function deleteCustomerCustomAttributeDefinition(string $key): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
key |
string |
Template, Required | The key of the custom attribute definition to delete. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type DeleteCustomerCustomAttributeDefinitionResponse
.
$key = 'key0';
$apiResponse = $customerCustomAttributesApi->deleteCustomerCustomAttributeDefinition($key);
if ($apiResponse->isSuccess()) {
$deleteCustomerCustomAttributeDefinitionResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Retrieves a customer-related custom attribute definition from a Square seller account.
To retrieve a custom attribute definition created by another application, the visibility
setting must be VISIBILITY_READ_ONLY
or VISIBILITY_READ_WRITE_VALUES
. Note that seller-defined custom attributes
(also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function retrieveCustomerCustomAttributeDefinition(string $key, ?int $version = null): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
key |
string |
Template, Required | The key of the custom attribute definition to retrieve. If the requesting application is not the definition owner, you must use the qualified key. |
version |
?int |
Query, Optional | The current version of the custom attribute definition, which 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 higher version if one exists. If the specified version is higher than the current version, Square returns a BAD_REQUEST error. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type RetrieveCustomerCustomAttributeDefinitionResponse
.
$key = 'key0';
$apiResponse = $customerCustomAttributesApi->retrieveCustomerCustomAttributeDefinition($key);
if ($apiResponse->isSuccess()) {
$retrieveCustomerCustomAttributeDefinitionResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Updates a customer-related custom attribute definition for a Square seller account.
Use this endpoint to update the following fields: name
, description
, visibility
, or the
schema
for a Selection
data type.
Only the definition owner can update a custom attribute definition. Note that sellers can view
all custom attributes in exported customer data, including those set to VISIBILITY_HIDDEN
.
function updateCustomerCustomAttributeDefinition(
string $key,
UpdateCustomerCustomAttributeDefinitionRequest $body
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
key |
string |
Template, Required | The key of the custom attribute definition to update. |
body |
UpdateCustomerCustomAttributeDefinitionRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type UpdateCustomerCustomAttributeDefinitionResponse
.
$key = 'key0';
$body = UpdateCustomerCustomAttributeDefinitionRequestBuilder::init(
CustomAttributeDefinitionBuilder::init()
->description('Update the description as desired.')
->visibility(CustomAttributeDefinitionVisibility::VISIBILITY_READ_ONLY)
->build()
)->build();
$apiResponse = $customerCustomAttributesApi->updateCustomerCustomAttributeDefinition(
$key,
$body
);
if ($apiResponse->isSuccess()) {
$updateCustomerCustomAttributeDefinitionResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Creates or updates custom attributes for customer profiles as a bulk operation.
Use this endpoint to set the value of one or more custom attributes for one or more customer profiles. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the CreateCustomerCustomAttributeDefinition endpoint.
This BulkUpsertCustomerCustomAttributes
endpoint accepts a map of 1 to 25 individual upsert
requests and returns a map of individual upsert responses. Each upsert request has a unique ID
and provides a customer ID and custom attribute. Each upsert response is returned with the ID
of the corresponding request.
To create or update a custom attribute owned by another application, the visibility
setting
must be VISIBILITY_READ_WRITE_VALUES
. Note that seller-defined custom attributes
(also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function bulkUpsertCustomerCustomAttributes(BulkUpsertCustomerCustomAttributesRequest $body): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
body |
BulkUpsertCustomerCustomAttributesRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type BulkUpsertCustomerCustomAttributesResponse
.
$body = BulkUpsertCustomerCustomAttributesRequestBuilder::init(
[
'key0' => BulkUpsertCustomerCustomAttributesRequestCustomerCustomAttributeUpsertRequestBuilder::init(
'customer_id8',
CustomAttributeBuilder::init()->build()
)->build(),
'key1' => BulkUpsertCustomerCustomAttributesRequestCustomerCustomAttributeUpsertRequestBuilder::init(
'customer_id8',
CustomAttributeBuilder::init()->build()
)->build()
]
)->build();
$apiResponse = $customerCustomAttributesApi->bulkUpsertCustomerCustomAttributes($body);
if ($apiResponse->isSuccess()) {
$bulkUpsertCustomerCustomAttributesResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Lists the custom attributes associated with a customer profile.
You can use the with_definitions
query parameter to also retrieve custom attribute definitions
in the same call.
When all response pages are retrieved, the results include all custom attributes that are
visible to the requesting application, including those that are owned by other applications
and set to VISIBILITY_READ_ONLY
or VISIBILITY_READ_WRITE_VALUES
.
function listCustomerCustomAttributes(
string $customerId,
?int $limit = null,
?string $cursor = null,
?bool $withDefinitions = false
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the target customer profile. |
limit |
?int |
Query, Optional | The maximum number of results to return in a single paged response. This limit is advisory. The response might contain more or fewer results. The minimum value is 1 and the maximum value is 100. The default value is 20. For more information, see Pagination. |
cursor |
?string |
Query, Optional | The cursor returned in the paged response from the previous call to this endpoint. Provide this cursor to retrieve the next page of results for your original request. For more information, see Pagination. |
withDefinitions |
?bool |
Query, Optional | Indicates whether to return the custom attribute definition in the definition field of eachcustom attribute. Set this parameter to true to get the name and description of each customattribute, information about the data type, or other definition details. The default value is false .Default: false |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type ListCustomerCustomAttributesResponse
.
$customerId = 'customer_id8';
$withDefinitions = false;
$apiResponse = $customerCustomAttributesApi->listCustomerCustomAttributes(
$customerId,
null,
null,
$withDefinitions
);
if ($apiResponse->isSuccess()) {
$listCustomerCustomAttributesResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Deletes a custom attribute associated with a customer profile.
To delete a custom attribute owned by another application, the visibility
setting must be
VISIBILITY_READ_WRITE_VALUES
. Note that seller-defined custom attributes
(also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function deleteCustomerCustomAttribute(string $customerId, string $key): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the target customer profile. |
key |
string |
Template, Required | The key of the custom attribute to delete. This key must match the key of a customattribute definition in the Square seller account. If the requesting application is not the definition owner, you must use the qualified key. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type DeleteCustomerCustomAttributeResponse
.
$customerId = 'customer_id8';
$key = 'key0';
$apiResponse = $customerCustomAttributesApi->deleteCustomerCustomAttribute(
$customerId,
$key
);
if ($apiResponse->isSuccess()) {
$deleteCustomerCustomAttributeResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Retrieves a custom attribute associated with a customer profile.
You can use the with_definition
query parameter to also retrieve the custom attribute definition
in the same call.
To retrieve a custom attribute owned by another application, the visibility
setting must be
VISIBILITY_READ_ONLY
or VISIBILITY_READ_WRITE_VALUES
. Note that seller-defined custom attributes
(also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function retrieveCustomerCustomAttribute(
string $customerId,
string $key,
?bool $withDefinition = false,
?int $version = null
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the target customer profile. |
key |
string |
Template, Required | The key of the custom attribute to retrieve. This key must match the key of a customattribute definition in the Square seller account. If the requesting application is not the definition owner, you must use the qualified key. |
withDefinition |
?bool |
Query, Optional | Indicates whether to return the custom attribute definition in the definition field ofthe custom attribute. Set this parameter to true to get the name and description of the customattribute, information about the data type, or other definition details. The default value is false .Default: false |
version |
?int |
Query, Optional | The current version of the custom attribute, which 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 higher version if one exists. If the specified version is higher than the current version, Square returns a BAD_REQUEST error. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type RetrieveCustomerCustomAttributeResponse
.
$customerId = 'customer_id8';
$key = 'key0';
$withDefinition = false;
$apiResponse = $customerCustomAttributesApi->retrieveCustomerCustomAttribute(
$customerId,
$key,
$withDefinition
);
if ($apiResponse->isSuccess()) {
$retrieveCustomerCustomAttributeResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Creates or updates a custom attribute for a customer profile.
Use this endpoint to set the value of a custom attribute for a specified customer profile. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the CreateCustomerCustomAttributeDefinition endpoint.
To create or update a custom attribute owned by another application, the visibility
setting
must be VISIBILITY_READ_WRITE_VALUES
. Note that seller-defined custom attributes
(also known as custom fields) are always set to VISIBILITY_READ_WRITE_VALUES
.
function upsertCustomerCustomAttribute(
string $customerId,
string $key,
UpsertCustomerCustomAttributeRequest $body
): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the target customer profile. |
key |
string |
Template, Required | The key of the custom attribute to create or update. This key must match the key of acustom attribute definition in the Square seller account. If the requesting application is not the definition owner, you must use the qualified key. |
body |
UpsertCustomerCustomAttributeRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type UpsertCustomerCustomAttributeResponse
.
$customerId = 'customer_id8';
$key = 'key0';
$body = UpsertCustomerCustomAttributeRequestBuilder::init(
CustomAttributeBuilder::init()->build()
)->build();
$apiResponse = $customerCustomAttributesApi->upsertCustomerCustomAttribute(
$customerId,
$key,
$body
);
if ($apiResponse->isSuccess()) {
$upsertCustomerCustomAttributeResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());