const customerGroupsApi = client.customerGroupsApi;
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.
async listCustomerGroups( cursor?: string,
limit?: number,
requestOptions?: RequestOptions): Promise<ApiResponse<ListCustomerGroupsResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
cursor |
string | undefined |
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 |
number | undefined |
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. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
try {
const { result, ...httpResponse } = await customerGroupsApi.listCustomerGroups();
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Creates a new customer group for a business.
The request must include the name
value of the group.
async createCustomerGroup( body: CreateCustomerGroupRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<CreateCustomerGroupResponse>>
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. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const body: CreateCustomerGroupRequest = {
group: {
name: 'Loyal Customers',
},
};
try {
const { result, ...httpResponse } = await customerGroupsApi.createCustomerGroup(body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Deletes a customer group as identified by the group_id
value.
async deleteCustomerGroup( groupId: string,
requestOptions?: RequestOptions): Promise<ApiResponse<DeleteCustomerGroupResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
groupId |
string |
Template, Required | The ID of the customer group to delete. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const groupId = 'group_id0';
try {
const { result, ...httpResponse } = await customerGroupsApi.deleteCustomerGroup(groupId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Retrieves a specific customer group as identified by the group_id
value.
async retrieveCustomerGroup( groupId: string,
requestOptions?: RequestOptions): Promise<ApiResponse<RetrieveCustomerGroupResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
groupId |
string |
Template, Required | The ID of the customer group to retrieve. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const groupId = 'group_id0';
try {
const { result, ...httpResponse } = await customerGroupsApi.retrieveCustomerGroup(groupId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Updates a customer group as identified by the group_id
value.
async updateCustomerGroup( groupId: string,
body: UpdateCustomerGroupRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<UpdateCustomerGroupResponse>>
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. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const groupId = 'group_id0';
const body: UpdateCustomerGroupRequest = {
group: {
name: 'Loyal Customers',
},
};
try {
const { result, ...httpResponse } = await customerGroupsApi.updateCustomerGroup(
groupId,
body
);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}