Clover REST API Basics with Postman
The Clover REST API allows apps and services to interact with Clover. However, you don’t need to build a complete web app to test out our REST API.
New to Clover’s REST API? Or want a refresher? Follow along as we demonstrate the basics of making Clover API requests with a little help from Postman, an API platform for building and using APIs.
Prerequisites
Before you can make API requests, you’ll need the following:
Postman
Download it for free or create an account to use Postman in a browser. There are other apps that offer similar functionality, but instructions in this tutorial use Postman.
Clover Sandbox account
Sign up for a free Sandbox developer account if you don’t have one yet. You will also create a test merchant connected to your account during this process.
Clover Sandbox app
See our instructions on how to set up a basic app. Your app should:
- Support Web as an App Type.
- Request at least the following Permissions:
— Inventory Read and Write (R/W)
— Orders R/W
— Payments R/W
— Merchant R
— Customers R
— Ecommerce - Include a Site URL as part of the app’s REST Configuration. The particular link depends on your preferred Postman workspace:
— For Postman on the Desktop, use:https://www.postman.com/oauth2/callback
— For Postman on the web, use:https://oauth.pstmn.io/v1/browser-callback
- Be installed to your test merchant.
Import the Clover API Tutorial collection
Open your Postman workspace. To import Clover’s example Postman collection:
- Download the Clover REST API Tutorial collection JSON
- Under the Collections tab, select the Import button
- Choose your downloaded JSON file
- Confirm the import
This collection uses a matching environment. Importing the environment is similar to importing a collection:
- Download the Clover Tutorial Environment JSON file
- Under the Environments tab, select the Import button
- Choose your downloaded JSON
- Confirm the import
Your workspace should now include:
- Collections > Clover REST API Tutorial, and
- Environments > Clover Tutorial Environment
Configure your Postman environment
The Clover tutorial collection comes with an environment template. You need to fill out a few details to get started.
- Click the Environments tab on the left navigation menu.
- Select the Clover Tutorial Environment.
- If this isn’t your active environment, do one of the following:
— Select the checkmark next to its name to set it as Active
— Select Clover Tutorial Environment from the Environments dropdown list - The base URL variables are already filled out:
— baseUrl: Since we’re testing in Sandbox, the base URL for all of our requests ishttps://sandbox.dev.clover.com
— ecommBaseUrl: We’ll use an Ecommerce endpoint to demonstrate paying for an order. Note that Clover Ecommerce requests use a slightly different base URL:https://scl-sandbox.dev.clover.com
- Add a Current Value to the following variables:
— appId: Your app’s 13-character ID
— appSecret: Your app’s secret key
— mId: Your test merchant’s 13-character ID
— (The rest of the IDs will be filled in as we go) - Make sure to Save your changes.
Generate an OAuth token
To authenticate your API requests, you’ll need to generate an access token. Clover uses the OAuth 2.0 framework for its API access tokens. Here’s how to generate one in Postman.
- Click the Collections tab on the left navigation menu.
- Select the Clover REST API Tutorial collection.
- Make sure you are viewing the Authorization tab for the collection.
- Check out the token configuration fields. These should already be filled out after adding values to the appId and appSecret variables in the previous section.
- Scroll to the bottom of the screen and select Get New Access Token.
- Log into your Clover account.
- If you have multiple test merchants, make sure to select the merchant associated with the mId you are using.
- Click Use Token.
You’re all set to start making Clover API requests!
Create your first order
Orders are often fundamental to the Clover experience. Most Clover objects, including payments, line items, and refunds, must be associated with an order. You will learn how to create an inventory item, create an order for that item, create more complex orders, and then search for your order. The following sections correspond to API requests in the collection.
Create an inventory item
You’ll first create an item for your merchant. Inventory items act as templates; when you add them to an order, the order’s line items inherit relevant details from the inventory item. You will need to provide at least a name and price for your new inventory item.
View the request’s Body tab in Postman for an example.
Review the returned response. In particular, you will reference the item ID later. A post-response script sets this ID as the environment’s itemId variable.
Click the Environment Quick Look button to confirm that the current value of itemId matches the returned item ID.
Note: You’ll notice that the price is set to 500 for this $5.00 item. This is because Clover stores money as integers rather than decimal values to avoid rounding errors. You can find a great explanation why we (and others) do this in this Computerphile video.
Create an order
Clover’s atomic order endpoint requires, at minimum, a line item. This is where your newly-created inventory item comes into play. You only need to reference the relevant item ID and your order will include the item’s name and price. When you submit the order creation request, it will automatically tally item prices, along with any modifications, discounts, and taxes (if set up) for the order total.
- Note the expected JSON structure in the request’s Body tab.
- Provide line items as a list, even if there’s only one of them.
- Enclose everything in an orderCart object.
{
"orderCart": {
"lineItems": [
{
"item": {
"id": "{{itemId}}"
}
}
]
}
}
Create an order with a discount
You can expand on this basic order structure to create orders with all sorts of variations. This request modifies the order structure to create an order with multiple line items and an order discount.
Similar to items, you can add a discount using the discount ID if you already have one. For this example, however, the body simply specifies a name for the discount and a percentage. You can instead use an amount for a flat discount.
Check out our docs on working with orders for even more variations on building an order request.
View your order
With your order ID in hand, you can quickly retrieve all of the order’s details using our REST API. Expansions provide even more information, such as associated line items and discounts.
If you’re following along, Postman has set your most recent order as the current orderId. If you want to review details on both of your previous orders, you can retrieve multiple orders using the GET {{baseUrl}}/v3/merchants/{{mId}}/orders
endpoint instead.
Add a gift card payment to an order
Now that you’re comfortable with creating orders, how about closing them out?
Most of the time, orders are paid for in person or using Clover’s Ecommerce API. To get a taste of using the Ecommerce API without all the encryption, you can pay for an order with a gift card tender instead of a credit card. Ecommerce’s Pay for an order endpoint closes out your order, automatically paying for the full order total by default.
Check out the documentation on each request in the Postman collection for a step-by-step guide through this process.
To explore implementing a full payment solution, learn more about our Ecommerce API for card-not-present (CNP) payments or our REST Pay API for card-present (CP) payments.
Additional API operations
Advanced query operations allow for greater control of response results when making requests. For merchants with large amounts of orders, payments, or inventory items, efficient queries are important to reduce the number of API calls and improve response time. This means your app will be more responsive and less likely to be rate limited.
The Additional V3 API Operations section of the Postman collection demonstrates how to perform the following operations:
- Expanding fields
- Filtering by
modifiedTime
- Applying multiple filters
- Sorting collections
- Displaying null fields
- Paging through results
What’s next
Now that you’ve nailed the basics, you can use your newfound skills to create your own app for our Clover App Market. For additional information, be sure to check out our Developer Docs, REST API Reference, and tutorial videos.