SquareConnect::CustomersApi

June 26, 2019 ยท View on GitHub

All URIs are relative to https://connect.squareup.com

MethodHTTP requestDescription
create_customerPOST /v2/customersCreateCustomer
create_customer_cardPOST /v2/customers/{customer_id}/cardsCreateCustomerCard
delete_customerDELETE /v2/customers/{customer_id}DeleteCustomer
delete_customer_cardDELETE /v2/customers/{customer_id}/cards/{card_id}DeleteCustomerCard
list_customersGET /v2/customersListCustomers
retrieve_customerGET /v2/customers/{customer_id}RetrieveCustomer
search_customersPOST /v2/customers/searchSearchCustomers
update_customerPUT /v2/customers/{customer_id}UpdateCustomer

create_customer

CreateCustomerResponse create_customer(body)

CreateCustomer

Creates a new customer for a business, which can have associated cards on file. 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

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

body = SquareConnect::CreateCustomerRequest.new # CreateCustomerRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.


begin
  #CreateCustomer
  result = api_instance.create_customer(body)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->create_customer: #{e}"
end

Parameters

NameTypeDescriptionNotes
bodyCreateCustomerRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

CreateCustomerResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

create_customer_card

CreateCustomerCardResponse create_customer_card(customer_id, body)

CreateCustomerCard

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. Cards on file are automatically updated on a monthly basis to confirm they are still valid and can be charged.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

customer_id = "customer_id_example" # String | The Square ID of the customer profile the card is linked to.

body = SquareConnect::CreateCustomerCardRequest.new # CreateCustomerCardRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.


begin
  #CreateCustomerCard
  result = api_instance.create_customer_card(customer_id, body)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->create_customer_card: #{e}"
end

Parameters

NameTypeDescriptionNotes
customer_idStringThe Square ID of the customer profile the card is linked to.
bodyCreateCustomerCardRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

CreateCustomerCardResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

delete_customer

DeleteCustomerResponse delete_customer(customer_id)

DeleteCustomer

Deletes a customer from a business, along with any linked cards on file. When two profiles are merged into a single profile, that profile is assigned a new customer_id. You must use the new customer_id to delete merged profiles.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

customer_id = "customer_id_example" # String | The ID of the customer to delete.


begin
  #DeleteCustomer
  result = api_instance.delete_customer(customer_id)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->delete_customer: #{e}"
end

Parameters

NameTypeDescriptionNotes
customer_idStringThe ID of the customer to delete.

Return type

DeleteCustomerResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

delete_customer_card

DeleteCustomerCardResponse delete_customer_card(customer_id, card_id)

DeleteCustomerCard

Removes a card on file from a customer.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

customer_id = "customer_id_example" # String | The ID of the customer that the card on file belongs to.

card_id = "card_id_example" # String | The ID of the card on file to delete.


begin
  #DeleteCustomerCard
  result = api_instance.delete_customer_card(customer_id, card_id)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->delete_customer_card: #{e}"
end

Parameters

NameTypeDescriptionNotes
customer_idStringThe ID of the customer that the card on file belongs to.
card_idStringThe ID of the card on file to delete.

Return type

DeleteCustomerCardResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

list_customers

ListCustomersResponse list_customers(opts)

ListCustomers

Lists a business's customers.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

opts = { 
  cursor: "cursor_example", # String | A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query.  See [Pagination](/basics/api101/pagination) for more information.
  sort_field: "sort_field_example", # String | Indicates how Customers should be sorted. Default: `DEFAULT`.
  sort_order: "sort_order_example" # String | Indicates whether Customers should be sorted in ascending (`ASC`) or descending (`DESC`) order. Default: `ASC`.
}

begin
  #ListCustomers
  result = api_instance.list_customers(opts)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->list_customers: #{e}"
end

Parameters

NameTypeDescriptionNotes
cursorStringA pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See Pagination for more information.[optional]
sort_fieldStringIndicates how Customers should be sorted. Default: `DEFAULT`.[optional]
sort_orderStringIndicates whether Customers should be sorted in ascending (`ASC`) or descending (`DESC`) order. Default: `ASC`.[optional]

Return type

ListCustomersResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

retrieve_customer

RetrieveCustomerResponse retrieve_customer(customer_id)

RetrieveCustomer

Returns details for a single customer.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

customer_id = "customer_id_example" # String | The ID of the customer to retrieve.


begin
  #RetrieveCustomer
  result = api_instance.retrieve_customer(customer_id)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->retrieve_customer: #{e}"
end

Parameters

NameTypeDescriptionNotes
customer_idStringThe ID of the customer to retrieve.

Return type

RetrieveCustomerResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

search_customers

SearchCustomersResponse search_customers(body)

SearchCustomers

Searches the customer profiles associated with a Square account. Calling SearchCustomers without an explicit query parameter returns all customer profiles ordered alphabetically based on given_name and family_name.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

body = SquareConnect::SearchCustomersRequest.new # SearchCustomersRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.


begin
  #SearchCustomers
  result = api_instance.search_customers(body)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->search_customers: #{e}"
end

Parameters

NameTypeDescriptionNotes
bodySearchCustomersRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

SearchCustomersResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

update_customer

UpdateCustomerResponse update_customer(customer_id, body)

UpdateCustomer

Updates the details of an existing customer. When two profiles are merged into a single profile, that profile is assigned a new customer_id. You must use the new customer_id to update merged profiles. You cannot edit a customer's cards on file with this endpoint. To make changes to a card on file, you must delete the existing card on file with the DeleteCustomerCard endpoint, then create a new one with the CreateCustomerCard endpoint.

Example

# load the gem
require 'square_connect'
# setup authorization
SquareConnect.configure do |config|
  # Configure OAuth2 access token for authorization: oauth2
  config.access_token = 'YOUR ACCESS TOKEN'
end

api_instance = SquareConnect::CustomersApi.new

customer_id = "customer_id_example" # String | The ID of the customer to update.

body = SquareConnect::UpdateCustomerRequest.new # UpdateCustomerRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.


begin
  #UpdateCustomer
  result = api_instance.update_customer(customer_id, body)
  p result
rescue SquareConnect::ApiError => e
  puts "Exception when calling CustomersApi->update_customer: #{e}"
end

Parameters

NameTypeDescriptionNotes
customer_idStringThe ID of the customer to update.
bodyUpdateCustomerRequestAn object containing the fields to POST for the request. See the corresponding object definition for field details.

Return type

UpdateCustomerResponse

Authorization

oauth2

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json