Recently, we added the new test mode feature to Salable which gives you a perfect place to experiment with Salable as well as perfect your products and plans before migrating them to live mode for users to subscribe to and use.
As part of this release, we mirrored our live mode functionality to test mode including actions such as creating and cancelling licenses using our API. So, in this post, we’re going to cover exactly how you can do that!
Setup
Before we can go about creating and cancelling our licenses using the API, we need to take care of some setup steps such as accessing test mode, creating our products and plans, and finally generating a new API key with the correct permissions.
To start with, you’ll need to have a Salable account (sign up here if you don’t already have one), once you’ve accessed your dashboard, you can access test mode by using the toggle on the bottom of the sidebar.
After you’ve successfully accessed test mode (you can confirm this by the test mode banner being shown at the top of the screen), we need to create a new product using the “Create New Product” button. Fill in the fields shown to you and for this guide, we can keep the product as a free one.
Once you have created your new product you should be taken to the product’s settings page. From here, we’ll need to create a few things such as a new capability, feature, and finally, a plan for us to create the license against.
With our plan created, we’re able to access its UUID the plan’s page inside the product’s settings page. This is important as we’ll need it in a moment when we perform our API requests to create the license, as all licenses need to be associated with a plan.
Finally, with our product and plan created, we can complete our setup by generating an API key that we can use to access the Salable API. To do this, head over to the settings page and then “API Keys” before clicking the “Create New API Key” button, naming your API Key, selecting all of the scopes under “Licenses” and then creating the API key by clicking “Create API Key”.
Creating and Cancelling Test Mode Licenses
With our plan and API key created, we’re ready to use the Salable API to create a new test mode license. To do this, we’ll be using Postman so we can easily hit the endpoints we need to but in practice, you’d want to send these requests from your application.
Creating a License
To create a new license using Postman, send a POST request to the URL https://api.salable.app/licenses, and inside the headers of the request ensure to include the API key you created earlier with a key of x-api-key. You can learn more about this on our API documentation here.
Then, inside the body of the request, you’ll want to add the below JSON, making sure to substitute the values for your plan UUID and the details of the license you’d like to create. Learn more about these fields and their meaning here.
Then, send your request and you should be returned the details of your newly created license. In the license details returned to us the isTest field should be true to inform us that it was indeed created in test mode. But, if you’d like to validate this further, navigate back to the dashboard in your browser and then check the licenses page in test mode where you should see the newly created active license.
Cancelling a License
Now, with our new test mode license created, let’s look at how to cancel it. To cancel it, we’re going to send a DELETE request to the endpoint https://api.salable.app/licenses/<LICENSE_UUID>, making sure to substitute in the license UUID you’d like to cancel as well as including your API key in the request headers again.
Once that request is sent, we should be returned a 204 status indicating that the cancellation was successful. To validate this further, refresh your licenses page on the dashboard and you should see that the previously active license is now marked as canceled.
In Summary
In this post, we looked at using Salable’s new test mode feature to create and cancel licenses using the Salable API to show how it would be perfect for use while developing new applications or experimenting with Salable. Check out our test mode documentation, and give it a go...
In this post, we’re going to look at how you can go about creating a new Trello Power-Up and monetise it using Salable so you can easily charge users to get access to...
In this post, we’re going to look at how you can go about creating a new Trello Power-Up and monetise it using Salable so you can easily charge users to get access to...
We’ve been working hard over the past 12 months to solve all the problems we had in running our SaaS business. This was everything from taking payment...
We’ve been working hard over the past 12 months to solve all the problems we had in running our SaaS business. This was everything from taking payment...