Creating a customer with Ruby

Adding customers to your Square account is a snap with a simple ruby script.

Reddit
LinkedIn

Customer management via API can be incredibly useful when syncing with other systems, automating marketing tasks, and more. If your Customer Directory looks empty and you want to add to it, take a look at the following ruby script:

# load the gem
require 'square_connect'

# setup authorization with a personal access token
SquareConnect.configure do |config|
  config.access_token = 'sq0atp-XXXXXXXXXXXXX'
end

#create a new API instance
api_instance = SquareConnect::CustomersApi.new

#Create a new customer request object and add information to it
customer = SquareConnect::CreateCustomerRequest.new 
customer.given_name = 'Tom'
customer.family_name = 'Jones'
customer.email_address = 'tom@example.com'


#Create the customer and print the results. 
result = api_instance.create_customer(customer)
p result

This script is fairly simple because Square’s Ruby SDK does most of the heavy lifting through authentication and parsing the data returned from the API. You can even run it easily from the command line with ruby CreateCustomer.rb. With a few modifications to the script you could loop through customer creation to import your customers from a different database or even a backup file that you have created in the past.

That’s it! If you have any questions or comments, feel free to reach out to us at @SquareDev on twitter or look at the official documentation.

First customer ready to go!🥇First customer ready to go!🥇