$customerGroupsApi = $client->getCustomerGroupsApi();
CustomerGroupsApi
- List Customer Groups
- Create Customer Group
- Delete Customer Group
- Retrieve Customer Group
- Update Customer Group
Retrieves the list of customer groups of a business.
function listCustomerGroups(?string $cursor = null, ?int $limit = null): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
cursor |
?string |
Query, Optional | A pagination cursor returned by a previous call to this endpoint. Provide this cursor to retrieve the next set of results for your original query. For more information, see Pagination. |
limit |
?int |
Query, Optional | The maximum number of results to return in a single page. This limit is advisory. The response might contain more or fewer results. If the limit is less than 1 or greater than 50, Square returns a 400 VALUE_TOO_LOW or 400 VALUE_TOO_HIGH error. The default value is 50.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 ListCustomerGroupsResponse
.
$apiResponse = $customerGroupsApi->listCustomerGroups();
if ($apiResponse->isSuccess()) {
$listCustomerGroupsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Creates a new customer group for a business.
The request must include the name
value of the group.
function createCustomerGroup(CreateCustomerGroupRequest $body): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateCustomerGroupRequest |
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 CreateCustomerGroupResponse
.
$body = CreateCustomerGroupRequestBuilder::init(
CustomerGroupBuilder::init(
'Loyal Customers'
)->build()
)->build();
$apiResponse = $customerGroupsApi->createCustomerGroup($body);
if ($apiResponse->isSuccess()) {
$createCustomerGroupResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Deletes a customer group as identified by the group_id
value.
function deleteCustomerGroup(string $groupId): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
groupId |
string |
Template, Required | The ID of the customer group to delete. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type DeleteCustomerGroupResponse
.
$groupId = 'group_id0';
$apiResponse = $customerGroupsApi->deleteCustomerGroup($groupId);
if ($apiResponse->isSuccess()) {
$deleteCustomerGroupResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Retrieves a specific customer group as identified by the group_id
value.
function retrieveCustomerGroup(string $groupId): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
groupId |
string |
Template, Required | The ID of the customer group to retrieve. |
This method returns a Square\Utils\ApiResponse
instance. The getResult()
method on this instance returns the response data which is of type RetrieveCustomerGroupResponse
.
$groupId = 'group_id0';
$apiResponse = $customerGroupsApi->retrieveCustomerGroup($groupId);
if ($apiResponse->isSuccess()) {
$retrieveCustomerGroupResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());
Updates a customer group as identified by the group_id
value.
function updateCustomerGroup(string $groupId, UpdateCustomerGroupRequest $body): ApiResponse
Parameter | Type | Tags | Description |
---|---|---|---|
groupId |
string |
Template, Required | The ID of the customer group to update. |
body |
UpdateCustomerGroupRequest |
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 UpdateCustomerGroupResponse
.
$groupId = 'group_id0';
$body = UpdateCustomerGroupRequestBuilder::init(
CustomerGroupBuilder::init(
'Loyal Customers'
)->build()
)->build();
$apiResponse = $customerGroupsApi->updateCustomerGroup(
$groupId,
$body
);
if ($apiResponse->isSuccess()) {
$updateCustomerGroupResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());