fbpx
Knowledge Base

Connecting to the Pressable API

Category: Tutorials | Last modified: August 15, 2021

The Pressable API allows you to communicate with your managed WordPress hosted Pressable site using an external application written in any programming language. Some of the things you can do with the API include managing your site and performing operations such as creating a site, deleting a site, renaming a site, cloning a site and a lot more.

How to connect to the API

To connect to the API you’ll need to create a new API app from the MyPressable API applications menu (MyPressable Control Panel > API Application > Create New API Application).

From this page you can give a custom name for your new API Application and assign the permission levels you’d like the app to have.

Once the API app is created a Client ID and Client Secret will be generated for you which you’ll need to connect to the API from any external application. Make sure you don’t share these tokens with anyone as they can be used to access your site.

How to Generate an Access/Bearer Token?

To successfully connect to the API you’ll need an Access Token (sometimes also referred to as a Bearer Token). To generate one go to the Pressable API docs, click on Usage, scroll down the page to Authorize – Copy the cURL snippet and replace it with your MyPressable login credentials and generated Client ID and Client Secret.

 

Ensure you don’t enter a password for -F grant_type=password \

Your end result should look similar to the snippet below:

curl -X POST \

-F grant_type=password \

-F client_id=enter-your-client-id-here \

-F client_secret=enter-your-client-secret-here \

-F email=youremail@email.com \

-F password=your-pressable-password-xxxxxxx \

https://my.pressable.com/auth/token

Go to the command terminal on your computer then paste the cURL snippet containing your connection credentials.

You should see a response similar to the one in the screenshot below.  From there you can copy the access_token as highlighted.

This Access Token will be used to authenticate requests made by your API application.

Note: The generated Access Token expires every 3599s which is approximately 59 mins or 1 hour. Once it expires you won’t be able to access the API and will need to generate a new one. If you are developing an app that consumes the Pressable API you’ll need to come up with a way to auto-generate the Access Token using a refresh token when it expires.

How to query the API?

You can use an API testing Tool like Postman to test your connection and also query the API.

To get started, download Postman from their official site. To connect to the Pressable API you’ll need your Access Token and the API URL you want to query. Examples of those endpoint URLs can be found on the API docs as seen in the screenshot below:

Pressable API basic endpoint URL

Examples of supported methods

A complete Pressable API endpoint URL should look similar to this: https://my.pressable.com/v1/121916/cache

How to use Postman API test tool to clear your Pressable site CDN cache

To successfully make a query to the API you’ll need to get the Pressable Site ID of the website you want to query.

Go to your MyPressable Control Panel and select the site you want to query.

 

In the browser address bar you should see your selected Pressable Site ID which you can copy for use in Postman.

You should now be able to form your endpoint URL to clear the cache of your website which should look like this with the Site ID added: https://my.pressable.com/v1/1219162/cache

/cache is the query object you’re querying which can be found in the API documentation under clear a site CDN cache.

 

Next, go to Postman and open a new window.

Enter the endpoint query URL containing your Site ID, e.g. https://my.pressable.com/v1/1219162/cache. To clear the CDN cache, we’ll make a DELETE request.

Under the space you entered the endpoint query URL click on Authorization > Bearer Token > add your Token.

 

Once it is added you can go ahead and click on Send to query the API to clear your CDN cache for the site. This should return a 200 response if the query was successful.

 

For more information on how to use the Pressable API please refer to the API docs or reach out to the Pressable support team via chat or sending an email to help@pressable.com