This article applies to Contextual Commerce. (Looking for Classic Commerce documentation?)
Table of Contents
What is the FastSpring API?
The FastSpring API is back-end service you can use to communicate with your FastSpring Store programatically, e.g. as an alternative to using the Dashboard. This is an advanced feature that requires some basic understanding of HTTP communication methods; GET, POST and DELETE are the primary methods used to communicate with the API.
Although the structure of the JSON data sent and received using the API is very similar to webhooks, the difference is that with webhooks, FastSpring proactively sends you data about subscribed events in near-real time, as the events happen. You create and arrange hosting for a script that will parse these posts as they come in. By contrast, using the FastSpring API, you initiate all communication with your FastSpring Store, on demand. You can request data from your Store using the GET method, and you can send data to your FastSpring Store (for example, creating a new product record) using the POST method. Using webhooks does not preclude the use of the API, nor does using the API prevent you from subscribing to and receiving webhook events. Indeed, one of the API endpoints (/events) is specifically designed to help you manage your webhook events.
Because it is a back-end service and does not have to interact with customers' Web browsers, using the API may be more secure compared to client-side methods of communicating with FastSpring, such as the Store Builder Library. (However, the Store Builder Library does offer enhanced security measures such as the secure payload, as well.)
Here are just a few practical examples of ways you might take advantage of the FastSpring API:
|Creating a batch of numerous product records without using the Dashboard||/products|
|Looking up a customer's account details in real-time, on demand||/accounts|
|Validating a customer's access to your service based on order details||/orders|
|Creating a custom order session for a specific customer that may override normal product pricing and pre-fill customer data||/sessions|
|Retrieving product details (description, price, image, etc.) from your FastSpring Store in real-time to populate your own web pages||/products|
Accessing the API
Address of the FastSpring API
API Credentials and Authentication
FastSpring API credentials consist of a single username and password for your entire Store. The username and password are used for "Basic Authentication" when making requests to the API.
To Obtain Your API Credentials
- Log on to the Dashboard and navigate to Integrations > API Credentials. Initially, the only option on this page will be the CREATE command.
- Click CREATE to generate your API Username and Password, which will be displayed when the page automatically refreshes.
- Make a note of the credentials and store them securely.
When preparing your database structure for storing values obtained from FastSpring via our JSON payloads you might assume the following datatypes:
- All "string" columns are VARCHAR 255, accordingly trimmed
- Encoding is UTF-8
- For numeric values (such as price or discount values) 2dp precision is expected ("2.00")
Available API Endpoints
Work with customer accounts and FastSpring-generated account IDs
|/coupons||Work with promotional coupons and their customer-facing codes||
|/events||Retrieve unprocessed webhook events and mark events processed||
|/orders||Work with order / transaction records||
Work with product records
|/returns||Work with returns and refunds||
|/sessions||Create a pre-loaded cart session for a specific customer with a FastSpring-
generated account IDs; you can load the session in a Popup Storefront
or provide the customer with a link to the session via a Web Storefront
|/subscriptions||Work with customers' recurring-billing subscription instances||
In order to maintain a responsive user experience, FastSpring may impose request rate limits on API calls originating from individual accounts. In the event that the rate limit is met, the response to the API request will be an http 404 response code (though this may be improved soon).
If you need to make a large number of API requests in a very short time, such that you may encounter rate limits, consider using batch requests where possible. For example, when retrieving authenticated account management URLs, you can obtain URLs for multiple account IDs in a single request:
More information about this example can be found in our Knowledge Base article about the accounts endpoint.