Postman is an application that simplifies sending HTTP requests to Shopify API endpoints. It allows you to quickly send and capture requests to the Shopify API and serves as a useful tool for getting started with the Shopify API or debugging your apps. It’s available as an OSX app.
Visit https://www.getpostman.com/ to download.
Get your Shopify API credentials
Once you have a Shopify store, you can quickly generate your API credentials using a private app.
In order to make authorized requests to the Shopify API from Postman, you will need to set your app's API key and password in the request header, as described below.
Working with Postman
Once you're up and running with Postman, you can use tabs to make a request to the Shopify API. You can use multiple tabs to create multiple API calls quickly.
To authorize to the Shopify API:
- Click Authorization and select Basic Auth from the Type dropdown.
- For Username and Password provide your store private API key and password respectively.
Once you've authenticated your request, you will need to specify the applicable HTTP method and API endpoint URL. Since you've already created a Shopify store, you can use Postman to get your store information.
To get your store information:
- Ensure that the request method dropdown menu is set to GET and specify the store API endpoint as follows
where "@store_url" is the domain of your specific Shopify store, and "shop" is the resource to be called.
- Click Send.
If the request was formatted correctly, the Store information is returned. To view as JSON select Pretty and JSON.
Note that the Store url format is as follows: https://apikey:password@hostname/admin/resource.json
As an alternate approach to using Postman, you can paste a properly formatted url (including API key and password) directly into the url bar. When you click Send the same data is returned to Postman in the Body of the response.
After you've successfully formatted an API request with Postman, you can save it into a Collection. Collections group together related API calls and are a great way to organize your work in Postman.
To create a Collection:
- Using the API call that you just sent, click the arrow next to Save.
- Click Save As and select an existing Collection or create a new Collection. You can also provide a Collection description to easily define the purpose of your Collection.
Adding additional calls to the Collection
Now that you've created a Collection, you can add an additional call to help organize your Shopify API calls. For this example, you will use a call that posts some data to your Shopify store. Since you've already created a store and used Postman to view your shop information, you can use the Product endpoint to create a new product.
To create a product and add it to your Collection:
- Open a new tab and enter the authorization information, as before.
- Select POST from the API actions dropdown, and enter the endpoint url for adding a product: https://<@store_url>/admin/products.json (remember to replace @store_url with your store's actual domain).
- Click Body and select "raw"; from the dropdown select "JSON (application/json)."
- Go to the Shopify API reference and navigate to the Product endpoint.
- Scroll down to the "Create a new product" POST call. Take note of the JSON syntax for posting a new product. For this tutorial we will copy the JSON of the Burton Custom Freestyle product.
- Add the JSON for your product in the Body of the request.
Click Send. Provided the request is properly formatted, the product response JSON will be returned to Postman with "Status: 201 created." Also note that the Headers of the request automatically update to show the addition of "Content-Type:application/json."
Add the POST request to your Shopify Postman Collection, as before.
You are now up-and-running with Postman and the Shopify API. Add as many API calls to your Collection as you would like.