Getting started with Postman and Square’s APIs
Being able to try out an API as quickly as possible is important when learning about its features. One of the tools to help you get up and…
Step 0: Install Postman
Before you can use Postman, you need to install it. Visit https://www.getpostman.com/ and download the preferred version for your system.
Step 1: Get the Postman collection
This step is easy. Just click on the big Run in Postman button on this page and you’ll be prompted to import the collection inside of Postman. You can also find this button in the Square API documentation.
Step 2: Set up your environment
Our collection makes use of Postman’s environment variables to easily manage your API credentials. Clicking the *Gear icon -> Manage Environments -> Add *should open up a dialog to create a new environment. You can call the environment square
or whatever your want. You will want to add a key of **access_token
**with a value of your access token to handle the authentication for each endpoint. Whenever you see a variable in double brackets like {{location_id}}
that indicates a variable that can be pulled from your environment.
Hopefully your environment looks something like this. ️
Step 3: Try out the APIs!
Now it’s time to try out some API calls in Postman!
Our collection has a few folders in it, each with different API calls to fulfil a different task, along with a V1 & V2 reference that contains all of the endpoints. Let’s look at the First Transaction folder. It has all of the calls for a standard e-commerce scenario of creating a customer, charging them, and viewing their resulting transaction. You should be able to run each request in order without any trouble. Relevant IDs in the responses will be automatically added to your environment for subsequent requests. You’ll need to use your API Sandbox credentials to use the testing card nonces.
-
**List locations **is the first step for almost any calls to the Connect APIs, since the location ID is in the URL for most requests. This one will add the first location that has credit card processing enabled to your environment under
location_id
. -
**Create a new customer. **In order to connect a customer to the transaction, we need to make sure there is a customer. The ID of the created customer will be automatically added to your environment under
customer_id
. -
Charge! For this request, we’ve added a fake card nonce, but in a real scenario you would generate the card nonce using the
SqPaymentForm
and do these transactions server-side. -
List Transactions. You can now list all the transactions for your location and view the one you just processed!
You can always learn more about the Square APIs in the documentation.
Want more? Sign up for our monthly developer newsletter or join our Slack community!