ICustomersApi customersApi = client.CustomersApi;
CustomersApi
- List Customers
- Create Customer
- Bulk Create Customers
- Bulk Delete Customers
- Bulk Retrieve Customers
- Bulk Update Customers
- Search Customers
- Delete Customer
- Retrieve Customer
- Update Customer
- Create Customer Card
- Delete Customer Card
- Remove Group From Customer
- Add Group to Customer
Lists customer profiles associated with a Square account.
Under normal operating conditions, newly created or updated customer profiles become available for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.
ListCustomersAsync(
string cursor = null,
int? limit = null,
string sortField = null,
string sortOrder = null,
bool? count = false)
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 specified limit is less than 1 or greater than 100, Square returns a 400 VALUE_TOO_LOW or 400 VALUE_TOO_HIGH error. The default value is 100.For more information, see Pagination. |
sortField |
string |
Query, Optional | Indicates how customers should be sorted. The default value is DEFAULT . |
sortOrder |
string |
Query, Optional | Indicates whether customers should be sorted in ascending (ASC ) ordescending ( DESC ) order.The default value is ASC . |
count |
bool? |
Query, Optional | Indicates whether to return the total count of customers in the count field of the response.The default value is false .Default: false |
Task<Models.ListCustomersResponse>
bool? count = false;
try
{
ListCustomersResponse result = await customersApi.ListCustomersAsync(
null,
null,
null,
null,
count
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Creates a new customer for a business.
You must provide at least one of the following values in your request to this endpoint:
given_name
family_name
company_name
email_address
phone_number
CreateCustomerAsync(
Models.CreateCustomerRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateCustomerRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.CreateCustomerResponse>
CreateCustomerRequest body = new CreateCustomerRequest.Builder()
.GivenName("Amelia")
.FamilyName("Earhart")
.EmailAddress("[email protected]")
.Address(
new Address.Builder()
.AddressLine1("500 Electric Ave")
.AddressLine2("Suite 600")
.Locality("New York")
.AdministrativeDistrictLevel1("NY")
.PostalCode("10003")
.Country("US")
.Build())
.PhoneNumber("+1-212-555-4240")
.ReferenceId("YOUR_REFERENCE_ID")
.Note("a customer")
.Build();
try
{
CreateCustomerResponse result = await customersApi.CreateCustomerAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Creates multiple customer profiles for a business.
This endpoint takes a map of individual create requests and returns a map of responses.
You must provide at least one of the following values in each create request:
given_name
family_name
company_name
email_address
phone_number
BulkCreateCustomersAsync(
Models.BulkCreateCustomersRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
BulkCreateCustomersRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.BulkCreateCustomersResponse>
BulkCreateCustomersRequest body = new BulkCreateCustomersRequest.Builder(
new Dictionary<string, BulkCreateCustomerData>
{
["8bb76c4f-e35d-4c5b-90de-1194cd9179f0"] = new BulkCreateCustomerData.Builder()
.GivenName("Amelia")
.FamilyName("Earhart")
.EmailAddress("[email protected]")
.Address(
new Address.Builder()
.AddressLine1("500 Electric Ave")
.AddressLine2("Suite 600")
.Locality("New York")
.AdministrativeDistrictLevel1("NY")
.PostalCode("10003")
.Country("US")
.Build())
.PhoneNumber("+1-212-555-4240")
.ReferenceId("YOUR_REFERENCE_ID")
.Note("a customer")
.Build(),
["d1689f23-b25d-4932-b2f0-aed00f5e2029"] = new BulkCreateCustomerData.Builder()
.GivenName("Marie")
.FamilyName("Curie")
.EmailAddress("[email protected]")
.Address(
new Address.Builder()
.AddressLine1("500 Electric Ave")
.AddressLine2("Suite 601")
.Locality("New York")
.AdministrativeDistrictLevel1("NY")
.PostalCode("10003")
.Country("US")
.Build())
.PhoneNumber("+1-212-444-4240")
.ReferenceId("YOUR_REFERENCE_ID")
.Note("another customer")
.Build(),
}
)
.Build();
try
{
BulkCreateCustomersResponse result = await customersApi.BulkCreateCustomersAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Deletes multiple customer profiles.
The endpoint takes a list of customer IDs and returns a map of responses.
BulkDeleteCustomersAsync(
Models.BulkDeleteCustomersRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
BulkDeleteCustomersRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.BulkDeleteCustomersResponse>
BulkDeleteCustomersRequest body = new BulkDeleteCustomersRequest.Builder(
new List<string>
{
"8DDA5NZVBZFGAX0V3HPF81HHE0",
"N18CPRVXR5214XPBBA6BZQWF3C",
"2GYD7WNXF7BJZW1PMGNXZ3Y8M8",
}
)
.Build();
try
{
BulkDeleteCustomersResponse result = await customersApi.BulkDeleteCustomersAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Retrieves multiple customer profiles.
This endpoint takes a list of customer IDs and returns a map of responses.
BulkRetrieveCustomersAsync(
Models.BulkRetrieveCustomersRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
BulkRetrieveCustomersRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.BulkRetrieveCustomersResponse>
BulkRetrieveCustomersRequest body = new BulkRetrieveCustomersRequest.Builder(
new List<string>
{
"8DDA5NZVBZFGAX0V3HPF81HHE0",
"N18CPRVXR5214XPBBA6BZQWF3C",
"2GYD7WNXF7BJZW1PMGNXZ3Y8M8",
}
)
.Build();
try
{
BulkRetrieveCustomersResponse result = await customersApi.BulkRetrieveCustomersAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Updates multiple customer profiles.
This endpoint takes a map of individual update requests and returns a map of responses.
You cannot use this endpoint to change cards on file. To make changes, use the Cards API or Gift Cards API.
BulkUpdateCustomersAsync(
Models.BulkUpdateCustomersRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
BulkUpdateCustomersRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.BulkUpdateCustomersResponse>
BulkUpdateCustomersRequest body = new BulkUpdateCustomersRequest.Builder(
new Dictionary<string, BulkUpdateCustomerData>
{
["8DDA5NZVBZFGAX0V3HPF81HHE0"] = new BulkUpdateCustomerData.Builder()
.EmailAddress("[email protected]")
.PhoneNumber("phone_number2")
.Note("updated customer note")
.Version(2L)
.Build(),
["N18CPRVXR5214XPBBA6BZQWF3C"] = new BulkUpdateCustomerData.Builder()
.GivenName("Marie")
.FamilyName("Curie")
.Version(0L)
.Build(),
}
)
.Build();
try
{
BulkUpdateCustomersResponse result = await customersApi.BulkUpdateCustomersAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Searches the customer profiles associated with a Square account using one or more supported query filters.
Calling SearchCustomers
without any explicit query filter returns all
customer profiles ordered alphabetically based on given_name
and
family_name
.
Under normal operating conditions, newly created or updated customer profiles become available for the search operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.
SearchCustomersAsync(
Models.SearchCustomersRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
SearchCustomersRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.SearchCustomersResponse>
SearchCustomersRequest body = new SearchCustomersRequest.Builder()
.Limit(2L)
.Query(
new CustomerQuery.Builder()
.Filter(
new CustomerFilter.Builder()
.CreationSource(
new CustomerCreationSourceFilter.Builder()
.Values(
new List<string>
{
"THIRD_PARTY",
})
.Rule("INCLUDE")
.Build())
.CreatedAt(
new TimeRange.Builder()
.StartAt("2018-01-01T00:00:00-00:00")
.EndAt("2018-02-01T00:00:00-00:00")
.Build())
.EmailAddress(
new CustomerTextFilter.Builder()
.Fuzzy("example.com")
.Build())
.GroupIds(
new FilterValue.Builder()
.All(
new List<string>
{
"545AXB44B4XXWMVQ4W8SBT3HHF",
})
.Build())
.Build())
.Sort(
new CustomerSort.Builder()
.Field("CREATED_AT")
.Order("ASC")
.Build())
.Build())
.Build();
try
{
SearchCustomersResponse result = await customersApi.SearchCustomersAsync(body);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Deletes a customer profile from a business. This operation also unlinks any associated cards on file.
To delete a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.
DeleteCustomerAsync(
string customerId,
long? version = null)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer to delete. |
version |
long? |
Query, Optional | The current version of the customer profile. As a best practice, you should include this parameter to enable optimistic concurrency control. For more information, see Delete a customer profile. |
Task<Models.DeleteCustomerResponse>
string customerId = "customer_id8";
try
{
DeleteCustomerResponse result = await customersApi.DeleteCustomerAsync(customerId);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Returns details for a single customer.
RetrieveCustomerAsync(
string customerId)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer to retrieve. |
Task<Models.RetrieveCustomerResponse>
string customerId = "customer_id8";
try
{
RetrieveCustomerResponse result = await customersApi.RetrieveCustomerAsync(customerId);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Updates a customer profile. This endpoint supports sparse updates, so only new or changed fields are required in the request.
To add or update a field, specify the new value. To remove a field, specify null
.
To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.
You cannot use this endpoint to change cards on file. To make changes, use the Cards API or Gift Cards API.
UpdateCustomerAsync(
string customerId,
Models.UpdateCustomerRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer to update. |
body |
UpdateCustomerRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.UpdateCustomerResponse>
string customerId = "customer_id8";
UpdateCustomerRequest body = new UpdateCustomerRequest.Builder()
.EmailAddress("[email protected]")
.PhoneNumber("phone_number2")
.Note("updated customer note")
.Version(2L)
.Build();
try
{
UpdateCustomerResponse result = await customersApi.UpdateCustomerAsync(
customerId,
body
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
This endpoint is deprecated.
Adds a card on file to an existing customer.
As with charges, calls to CreateCustomerCard
are idempotent. Multiple
calls with the same card nonce return the same card record that was created
with the provided nonce during the first call.
CreateCustomerCardAsync(
string customerId,
Models.CreateCustomerCardRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The Square ID of the customer profile the card is linked to. |
body |
CreateCustomerCardRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Task<Models.CreateCustomerCardResponse>
string customerId = "customer_id8";
CreateCustomerCardRequest body = new CreateCustomerCardRequest.Builder(
"YOUR_CARD_NONCE"
)
.BillingAddress(
new Address.Builder()
.AddressLine1("500 Electric Ave")
.AddressLine2("Suite 600")
.Locality("New York")
.AdministrativeDistrictLevel1("NY")
.PostalCode("10003")
.Country("US")
.Build())
.CardholderName("Amelia Earhart")
.Build();
try
{
CreateCustomerCardResponse result = await customersApi.CreateCustomerCardAsync(
customerId,
body
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
This endpoint is deprecated.
Removes a card on file from a customer.
DeleteCustomerCardAsync(
string customerId,
string cardId)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer that the card on file belongs to. |
cardId |
string |
Template, Required | The ID of the card on file to delete. |
Task<Models.DeleteCustomerCardResponse>
string customerId = "customer_id8";
string cardId = "card_id4";
try
{
DeleteCustomerCardResponse result = await customersApi.DeleteCustomerCardAsync(
customerId,
cardId
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Removes a group membership from a customer.
The customer is identified by the customer_id
value
and the customer group is identified by the group_id
value.
RemoveGroupFromCustomerAsync(
string customerId,
string groupId)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer to remove from the group. |
groupId |
string |
Template, Required | The ID of the customer group to remove the customer from. |
Task<Models.RemoveGroupFromCustomerResponse>
string customerId = "customer_id8";
string groupId = "group_id0";
try
{
RemoveGroupFromCustomerResponse result = await customersApi.RemoveGroupFromCustomerAsync(
customerId,
groupId
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}
Adds a group membership to a customer.
The customer is identified by the customer_id
value
and the customer group is identified by the group_id
value.
AddGroupToCustomerAsync(
string customerId,
string groupId)
Parameter | Type | Tags | Description |
---|---|---|---|
customerId |
string |
Template, Required | The ID of the customer to add to a group. |
groupId |
string |
Template, Required | The ID of the customer group to add the customer to. |
Task<Models.AddGroupToCustomerResponse>
string customerId = "customer_id8";
string groupId = "group_id0";
try
{
AddGroupToCustomerResponse result = await customersApi.AddGroupToCustomerAsync(
customerId,
groupId
);
}
catch (ApiException e)
{
// TODO: Handle exception here
Console.WriteLine(e.Message);
}