What can I do with Prerender.io Rest API?
  • 05 Jan 2024
  • 3 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

What can I do with Prerender.io Rest API?

  • Dark
    Light
  • PDF

Article Summary

Swagger

All of our current API endpoints are also available via Swagger.

Recache

You can use the recache API to cache a URL for the first time or recache a URL cached previously. This POST request needs to be in JSON format; otherwise, it won't work.

The recache API is great for keeping your costs down, letting you set your cache expiration to a high value by using the recache API to supplement pages that change more often.

URL

https://api.prerender.io/recache

Params

{
	"prerenderToken": "YOUR_TOKEN",
	"url": "http://www.example.com/url/to/recache"
}

Example

curl -H "Content-Type: application/json" -d '{"prerenderToken": "YOUR\_TOKEN", "url": "http://www.example.com/"}' https://api.prerender.io/recache

Recaching Multiple URLs

The recache API can take up to 1,000 URLs per request. Make sure to change the parameter to "urls" if you want to add more than 1 url per request.

Params

{ 	
	"prerenderToken": "YOUR_TOKEN", 	
	"urls": [
        "http://www.example.com/url/to/recache", 
        "http://www.example.com/url/to/recache2"
    ] 
}

Example

curl -H "Content-Type: application/json" -d '{"prerenderToken": "YOUR\_TOKEN", "urls": \["http://www.example.com/url/to/recache", "http://www.example.com/url/to/recache2"\]}' https://api.prerender.io/recache

You can also use our Python script to cache or recache URLs in bulk from a text file or a sitemap's URL.
the script and it's documentation can be found here: Automate URL Caching with Prerender Recache Script

Recaching mobile pages

To recache mobile pages add "adaptiveType": "mobile" to the recache request.

Params

{
	"prerenderToken": "YOUR_TOKEN",
	"url": "http://www.example.com/url/to/recache",
	"adaptiveType": "mobile"
}

Example

curl -H "Content-Type: application/json" -d '{"prerenderToken": "YOUR\_TOKEN", "url": "http://www.example.com/", "adaptiveType": "mobile"}' https://api.prerender.io/recache

Search

The search API lets you search for cached URLs within your account and see their cache status.

URL

https://api.prerender.io/search

Params

{
    "prerenderToken": "YOUR TOKEN",
    "query": "example.com/path",
    "exactMatch": "https://example.com/path",
    "start": 0,
    "adaptiveType": "desktop"
}
  • The query parameter performs a 'contains' query. Optional parameter
  • exactMatch returns the results where the URL is fully identical. Optional parameter. If both query and exactMatch are present only exactMatch will be used.
  • start is for pagination. The search returns 200 URLs. If you want to get then next 200 you can set the start parameter to 200. 400 for the next batch, etc. Optional parameter.
  • adaptiveType: Can be "mobile" or "desktop". If you have both mobile and desktop version of a page yu can filter for them this way. Optional parameter

Sitemap

The sitemap API lets you add new URLs via sitemap XML files. Existing URLs will not be recached.

URL

https://api.prerender.io/sitemap

Params

{
  "prerenderToken": "YOUR TOKEN",
  "url": "https://www.sitemaps.org/sitemap.xml"
}

Example

curl -H "Content-Type: application/json" -d '{"prerenderToken": "YOUR_TOKEN", "url": "https://www.sitemaps.org/sitemap.xml"}' https://api.prerender.io/sitemap

Clear cache

This API will enable you to clear your cache, totally or partially. It is only available for users in our current plans. Users in our legacy plans will not have access to this API and should reach out to us to clear their cache. This call schedules a clear job. The job usually runs quite fast, but it is dependent on the size of the cache. It’s possible to check the job’s status, as shown below. There can only be one scheduled job per user. This is a POST request with two parameters.

URL

https://api.prerender.io/cache-clear

Params

{
 "prerenderToken": "YOUR TOKEN",
 "query”: “https://example.com%"
}

prerenderToken - Your API token

query - This query will be inserted into an SQL-like condition. So “%” and “?” act as a wildcard.

http://example.com% - adding “%” after a URL will delete everything that begins with the string before “%”. In this example, all cache that starts with https://example.com will be deleted.

Example

curl -X POST -H “Content-Type: application/json” -d ‘{“prerenderToken”: “YOUR TOKEN”, “query”: “https://example.com%“}’ https://api.prerender.io/cache-clear

Return values

200 - Cache clear queued
403 - Cache clear in progress

Check cache clear job status

This is a GET request. You will need to provide your API token in the URL.

URL

https://api.prerender.io/cache-clear-status

Example

curl https://api.prerender.io/cache-clear-status/YOURTOKEN

Return values

403 - in progress
200 - not queued

Was this article helpful?