Listing your locations with Python

Listing your locations with Python

Getting your location details should be the easiest part of your integration.

Listing your locations programmatically can be important for managing applications for large companies or even multiple companies. Here is how you can get a list of your locations using our Python SDK.

Prepare

The first thing you’ll need to do is make sure that you have python working and install Square’s Python SDK. You can find the installation instructions here: https://github.com/square/connect-python-sdk#installation--usage

The Code

# use Square's SDK to make your job easier
import squareconnect
from squareconnect.apis.locations_api import LocationsApi

# setup authorization with your access token
squareconnect.configuration.access_token = 'XXXXXXXXXXXXX'

# create an instance of the Location API class
api_instance = LocationsApi()

# call the API to list available locations and print the results
api_response = api_instance.list_locations()
print (api_response.locations)

You’ll have to replace the XXXXXXXXX with your access token from your Square Developer Portal. but then you should be able to save the above code to a file ListLocations.py and then run the file with:

python ListLocations.py

Then, your locations should print on on this screen:

Hope you find this post on listing locations useful! Remember that you can now also get your location ID’s from the Developer Portal.

Table Of Contents
View More Articles ›