Skip to content

Latest commit

 

History

History
225 lines (163 loc) · 6.63 KB

customer-groups.md

File metadata and controls

225 lines (163 loc) · 6.63 KB

Customer Groups

const customerGroupsApi = client.customerGroupsApi;

Class Name

CustomerGroupsApi

Methods

List Customer Groups

Retrieves the list of customer groups of a business.

async listCustomerGroups(  cursor?: string,
  limit?: number,
requestOptions?: RequestOptions): Promise<ApiResponse<ListCustomerGroupsResponse>>

Parameters

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.

Response Type

ListCustomerGroupsResponse

Example Usage

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;
  }
}

Create Customer Group

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>>

Parameters

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.

Response Type

CreateCustomerGroupResponse

Example Usage

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;
  }
}

Delete Customer Group

Deletes a customer group as identified by the group_id value.

async deleteCustomerGroup(  groupId: string,
requestOptions?: RequestOptions): Promise<ApiResponse<DeleteCustomerGroupResponse>>

Parameters

Parameter Type Tags Description
groupId string Template, Required The ID of the customer group to delete.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

DeleteCustomerGroupResponse

Example Usage

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;
  }
}

Retrieve Customer Group

Retrieves a specific customer group as identified by the group_id value.

async retrieveCustomerGroup(  groupId: string,
requestOptions?: RequestOptions): Promise<ApiResponse<RetrieveCustomerGroupResponse>>

Parameters

Parameter Type Tags Description
groupId string Template, Required The ID of the customer group to retrieve.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

RetrieveCustomerGroupResponse

Example Usage

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;
  }
}

Update Customer Group

Updates a customer group as identified by the group_id value.

async updateCustomerGroup(  groupId: string,
  body: UpdateCustomerGroupRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<UpdateCustomerGroupResponse>>

Parameters

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.

Response Type

UpdateCustomerGroupResponse

Example Usage

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;
  }
}