Skip to content

Latest commit

 

History

History
191 lines (136 loc) · 5.05 KB

locations.md

File metadata and controls

191 lines (136 loc) · 5.05 KB

Locations

locations_api = client.locations

Class Name

LocationsApi

Methods

List Locations

Provides information of all locations of a business.

Many Square API endpoints require a location_id parameter. The id field of the Location objects returned by this endpoint correspond to that location_id parameter.

def list_locations

Response Type

List Locations Response Hash

Example Usage

result = locations_api.list_locations()

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Create Location

Creates a location.

def create_location(body:)

Parameters

Parameter Type Tags Description
body Create Location Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Create Location Response Hash

Example Usage

body = {}
body[:location] = {}
body[:location][:id] = 'id0'
body[:location][:name] = 'New location name'
body[:location][:address] = {}
body[:location][:address][:address_line_1] = '1234 Peachtree St. NE'
body[:location][:address][:address_line_2] = 'address_line_26'
body[:location][:address][:address_line_3] = 'address_line_32'
body[:location][:address][:locality] = 'Atlanta'
body[:location][:address][:sublocality] = 'sublocality6'
body[:location][:address][:administrative_district_level_1] = 'GA'
body[:location][:address][:postal_code] = '30309'
body[:location][:timezone] = 'timezone0'
body[:location][:capabilities] = ['AUTOMATIC_TRANSFERS', 'CREDIT_CARD_PROCESSING', 'AUTOMATIC_TRANSFERS']
body[:location][:description] = 'My new location.'
body[:location][:facebook_url] = 'null'

result = locations_api.create_location(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Retrieve Location

Retrieves details of a location. You can specify "main" as the location ID to retrieve details of the main location.

def retrieve_location(location_id:)

Parameters

Parameter Type Tags Description
location_id String Template, Required The ID of the location to retrieve. If you specify the string "main",
then the endpoint returns the main location.

Response Type

Retrieve Location Response Hash

Example Usage

location_id = 'location_id4'

result = locations_api.retrieve_location(location_id: location_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Update Location

Updates a location.

def update_location(location_id:,
                    body:)

Parameters

Parameter Type Tags Description
location_id String Template, Required The ID of the location to update.
body Update Location Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Update Location Response Hash

Example Usage

location_id = 'location_id4'
body = {}
body[:location] = {}
body[:location][:id] = 'id0'
body[:location][:name] = 'Updated nickname'
body[:location][:address] = {}
body[:location][:address][:address_line_1] = '1234 Peachtree St. NE'
body[:location][:address][:address_line_2] = 'address_line_26'
body[:location][:address][:address_line_3] = 'address_line_32'
body[:location][:address][:locality] = 'Atlanta'
body[:location][:address][:sublocality] = 'sublocality6'
body[:location][:address][:administrative_district_level_1] = 'GA'
body[:location][:address][:postal_code] = '30309'
body[:location][:timezone] = 'timezone0'
body[:location][:capabilities] = ['AUTOMATIC_TRANSFERS', 'CREDIT_CARD_PROCESSING', 'AUTOMATIC_TRANSFERS']
body[:location][:business_hours] = {}
body[:location][:business_hours][:periods] = []


body[:location][:business_hours][:periods][0] = {}
body[:location][:business_hours][:periods][0][:day_of_week] = 'MON'
body[:location][:business_hours][:periods][0][:start_local_time] = '09:00'
body[:location][:business_hours][:periods][0][:end_local_time] = '17:00'

body[:location][:description] = 'Updated description'
body[:location][:twitter_username] = 'twitter'
body[:location][:instagram_username] = 'instagram'
body[:location][:facebook_url] = 'null'

result = locations_api.update_location(location_id: location_id, body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end