Skip to content

Latest commit

 

History

History
516 lines (385 loc) · 15.8 KB

customers.md

File metadata and controls

516 lines (385 loc) · 15.8 KB

Customers

ICustomersApi customersApi = client.CustomersApi;

Class Name

CustomersApi

Methods

List Customers

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)

Parameters

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) or
descending (DESC) order.

The default value is ASC.

Response Type

Task<Models.ListCustomersResponse>

Example Usage

string cursor = "cursor6";
int? limit = 172;
string sortField = "DEFAULT";
string sortOrder = "DESC";

try
{
    ListCustomersResponse result = await customersApi.ListCustomersAsync(cursor, limit, sortField, sortOrder);
}
catch (ApiException e){};

Create Customer

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)

Parameters

Parameter Type Tags Description
body Models.CreateCustomerRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.CreateCustomerResponse>

Example Usage

var bodyAddress = new Address.Builder()
    .AddressLine1("500 Electric Ave")
    .AddressLine2("Suite 600")
    .AddressLine3("address_line_38")
    .Locality("New York")
    .Sublocality("sublocality2")
    .AdministrativeDistrictLevel1("NY")
    .PostalCode("10003")
    .Country("US")
    .Build();
var body = new CreateCustomerRequest.Builder()
    .IdempotencyKey("idempotency_key2")
    .GivenName("Amelia")
    .FamilyName("Earhart")
    .CompanyName("company_name2")
    .Nickname("nickname2")
    .EmailAddress("Amelia.Earhart@example.com")
    .Address(bodyAddress)
    .PhoneNumber("1-212-555-4240")
    .ReferenceId("YOUR_REFERENCE_ID")
    .Note("a customer")
    .Build();

try
{
    CreateCustomerResponse result = await customersApi.CreateCustomerAsync(body);
}
catch (ApiException e){};

Search Customers

Searches the customer profiles associated with a Square account using a supported query filter.

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)

Parameters

Parameter Type Tags Description
body Models.SearchCustomersRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.SearchCustomersResponse>

Example Usage

var bodyQueryFilterCreationSourceValues = new IList<string>();
bodyQueryFilterCreationSourceValues.Add("THIRD_PARTY");
var bodyQueryFilterCreationSource = new CustomerCreationSourceFilter.Builder()
    .Values(bodyQueryFilterCreationSourceValues)
    .Rule("INCLUDE")
    .Build();
var bodyQueryFilterCreatedAt = new TimeRange.Builder()
    .StartAt("2018-01-01T00:00:00-00:00")
    .EndAt("2018-02-01T00:00:00-00:00")
    .Build();
var bodyQueryFilterUpdatedAt = new TimeRange.Builder()
    .StartAt("start_at4")
    .EndAt("end_at8")
    .Build();
var bodyQueryFilterEmailAddress = new CustomerTextFilter.Builder()
    .Exact("exact0")
    .Fuzzy("example.com")
    .Build();
var bodyQueryFilterPhoneNumber = new CustomerTextFilter.Builder()
    .Exact("exact0")
    .Fuzzy("fuzzy6")
    .Build();
var bodyQueryFilterGroupIdsAll = new IList<string>();
bodyQueryFilterGroupIdsAll.Add("545AXB44B4XXWMVQ4W8SBT3HHF");
var bodyQueryFilterGroupIdsAny = new IList<string>();
bodyQueryFilterGroupIdsAny.Add("any0");
bodyQueryFilterGroupIdsAny.Add("any1");
bodyQueryFilterGroupIdsAny.Add("any2");
var bodyQueryFilterGroupIdsNone = new IList<string>();
bodyQueryFilterGroupIdsNone.Add("none5");
bodyQueryFilterGroupIdsNone.Add("none6");
var bodyQueryFilterGroupIds = new FilterValue.Builder()
    .All(bodyQueryFilterGroupIdsAll)
    .Any(bodyQueryFilterGroupIdsAny)
    .None(bodyQueryFilterGroupIdsNone)
    .Build();
var bodyQueryFilter = new CustomerFilter.Builder()
    .CreationSource(bodyQueryFilterCreationSource)
    .CreatedAt(bodyQueryFilterCreatedAt)
    .UpdatedAt(bodyQueryFilterUpdatedAt)
    .EmailAddress(bodyQueryFilterEmailAddress)
    .PhoneNumber(bodyQueryFilterPhoneNumber)
    .GroupIds(bodyQueryFilterGroupIds)
    .Build();
var bodyQuerySort = new CustomerSort.Builder()
    .Field("CREATED_AT")
    .Order("ASC")
    .Build();
var bodyQuery = new CustomerQuery.Builder()
    .Filter(bodyQueryFilter)
    .Sort(bodyQuerySort)
    .Build();
var body = new SearchCustomersRequest.Builder()
    .Cursor("cursor0")
    .Limit(2L)
    .Query(bodyQuery)
    .Build();

try
{
    SearchCustomersResponse result = await customersApi.SearchCustomersAsync(body);
}
catch (ApiException e){};

Delete Customer

Deletes a customer profile from a business. This operation also unlinks any associated cards on file.

As a best practice, you should include the version field in the request to enable optimistic concurrency control. The value must be set to the current version of the customer profile.

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)

Parameters

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.

Response Type

Task<Models.DeleteCustomerResponse>

Example Usage

string customerId = "customer_id8";
long? version = 172L;

try
{
    DeleteCustomerResponse result = await customersApi.DeleteCustomerAsync(customerId, version);
}
catch (ApiException e){};

Retrieve Customer

Returns details for a single customer.

RetrieveCustomerAsync(
    string customerId)

Parameters

Parameter Type Tags Description
customerId string Template, Required The ID of the customer to retrieve.

Response Type

Task<Models.RetrieveCustomerResponse>

Example Usage

string customerId = "customer_id8";

try
{
    RetrieveCustomerResponse result = await customersApi.RetrieveCustomerAsync(customerId);
}
catch (ApiException e){};

Update Customer

Updates a customer profile. To change an attribute, specify the new value. To remove an attribute, specify the value as an empty string or empty object.

As a best practice, you should include the version field in the request to enable optimistic concurrency control. The value must be set to the current version of the customer profile.

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)

Parameters

Parameter Type Tags Description
customerId string Template, Required The ID of the customer to update.
body Models.UpdateCustomerRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.UpdateCustomerResponse>

Example Usage

string customerId = "customer_id8";
var body = new UpdateCustomerRequest.Builder()
    .GivenName("given_name8")
    .FamilyName("family_name0")
    .CompanyName("company_name2")
    .Nickname("nickname2")
    .EmailAddress("New.Amelia.Earhart@example.com")
    .PhoneNumber("")
    .Note("updated customer note")
    .Version(2L)
    .Build();

try
{
    UpdateCustomerResponse result = await customersApi.UpdateCustomerAsync(customerId, body);
}
catch (ApiException e){};

Create Customer Card

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)

Parameters

Parameter Type Tags Description
customerId string Template, Required The Square ID of the customer profile the card is linked to.
body Models.CreateCustomerCardRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Task<Models.CreateCustomerCardResponse>

Example Usage

string customerId = "customer_id8";
var bodyBillingAddress = new Address.Builder()
    .AddressLine1("500 Electric Ave")
    .AddressLine2("Suite 600")
    .AddressLine3("address_line_38")
    .Locality("New York")
    .Sublocality("sublocality2")
    .AdministrativeDistrictLevel1("NY")
    .PostalCode("10003")
    .Country("US")
    .Build();
var body = new CreateCustomerCardRequest.Builder(
        "YOUR_CARD_NONCE")
    .BillingAddress(bodyBillingAddress)
    .CardholderName("Amelia Earhart")
    .VerificationToken("verification_token0")
    .Build();

try
{
    CreateCustomerCardResponse result = await customersApi.CreateCustomerCardAsync(customerId, body);
}
catch (ApiException e){};

Delete Customer Card

This endpoint is deprecated.

Removes a card on file from a customer.

DeleteCustomerCardAsync(
    string customerId,
    string cardId)

Parameters

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.

Response Type

Task<Models.DeleteCustomerCardResponse>

Example Usage

string customerId = "customer_id8";
string cardId = "card_id4";

try
{
    DeleteCustomerCardResponse result = await customersApi.DeleteCustomerCardAsync(customerId, cardId);
}
catch (ApiException e){};

Remove Group From Customer

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)

Parameters

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.

Response Type

Task<Models.RemoveGroupFromCustomerResponse>

Example Usage

string customerId = "customer_id8";
string groupId = "group_id0";

try
{
    RemoveGroupFromCustomerResponse result = await customersApi.RemoveGroupFromCustomerAsync(customerId, groupId);
}
catch (ApiException e){};

Add Group to Customer

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)

Parameters

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.

Response Type

Task<Models.AddGroupToCustomerResponse>

Example Usage

string customerId = "customer_id8";
string groupId = "group_id0";

try
{
    AddGroupToCustomerResponse result = await customersApi.AddGroupToCustomerAsync(customerId, groupId);
}
catch (ApiException e){};