Skip to content

Latest commit

 

History

History
181 lines (125 loc) · 4.96 KB

locations.md

File metadata and controls

181 lines (125 loc) · 4.96 KB

Locations

locations_api = client.locations

Class Name

LocationsApi

Methods

List Locations

Provides details about all of the seller's locations, including those with an inactive status.

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. Creating new locations allows for separate configuration of receipt layouts, item prices, and sales reports. Developers can use locations to separate sales activity through applications that integrate with Square from sales activity elsewhere in a seller's account. Locations created programmatically with the Locations API last forever and are visible to the seller for their own management. Therefore, ensure that each location has a sensible and unique name.

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][:name] = 'Midtown'
body[:location][:address] = {}
body[:location][:address][:address_line_1] = '1234 Peachtree St. NE'
body[:location][:address][:locality] = 'Atlanta'
body[:location][:address][:administrative_district_level_1] = 'GA'
body[:location][:address][:postal_code] = '30309'
body[:location][:description] = 'Midtown Atlanta store'

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 single location. 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. Specify the string
"main" to return 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][:business_hours] = {}
body[:location][:business_hours][:periods] = []


body[:location][:business_hours][:periods][0] = {}
body[:location][:business_hours][:periods][0][:day_of_week] = 'FRI'
body[:location][:business_hours][:periods][0][:start_local_time] = '07:00'
body[:location][:business_hours][:periods][0][:end_local_time] = '18:00'

body[:location][:business_hours][:periods][1] = {}
body[:location][:business_hours][:periods][1][:day_of_week] = 'SAT'
body[:location][:business_hours][:periods][1][:start_local_time] = '07:00'
body[:location][:business_hours][:periods][1][:end_local_time] = '18:00'

body[:location][:business_hours][:periods][2] = {}
body[:location][:business_hours][:periods][2][:day_of_week] = 'SUN'
body[:location][:business_hours][:periods][2][:start_local_time] = '09:00'
body[:location][:business_hours][:periods][2][:end_local_time] = '15:00'

body[:location][:description] = 'Midtown Atlanta store - Open weekends'

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

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