How to flush cache with the Yottaa API

You can use Yottaa's API to do a few different things. In this article, we discuss how to flush cache from an entire domain and purge individual files using the API.

First, you'll have to get your API key and User ID key on the API Key section of the Account page:

(Your actual API key will display where appropriate)

You'll also need the Site ID. To find this, go to the Site page in the Yottaa portal. In there, you'll find the Site ID in the URL. It's highlighted in the URL by the blue box: 

You do not need to include the "/" on either end. This is the "Site ID." You will also need the profile ID. To get the profile ID, click on the General, Mobile, or Search Engine tab on the optimizer page. The URL will now have an "?id=" and the profile ID, as shown in the blue box here:

Now that you have your User_ID, Profile_ID, Site_ID and Yottaa-API-Key, you are ready to flush the cache of your site via API.

Flushing cache for your entire domain

Option 1: Command Line (cURL)

Unix:

The following command is meant to be used in a Unix based operating system.  Input the user ID, profile ID, site ID, and API key in their respective spaces marked by "***" in the following curl command.

curl -kH "YOTTAA-API-KEY: ***API_KEY***" -X PUT "https://api.yottaa.com/sites/***Site_ID***/flush_cache?user_id=***User_ID***&profile_id=***Profile_ID***"

You will receive the following response if the API server properly receives the request.

{"success":true}

Windows:

The curl command is not natively available for Windows operating system.  To get around this, you will need to download the curl.exe from the following site.  Make sure to click on the download in the Packages section and NOT the Source Archives section.

http://curl.haxx.se/download.html  

After downloading and unzipping the package to a directory of your choice, you should have a curl.exe file.  Open a command prompt and navigate to the curl.exe file.  Input the user ID, profile ID, site ID, and API key in their respective spaces marked by "***" in the following curl command.

curl -kH "YOTTAA-API-KEY: ***API_KEY***" -X PUT "https://api.yottaa.com/sites/***Site_ID***/flush_cache?user_id=***User_ID***&profile_id=***Profile_ID***"

You will receive the following response if the API server properly receives the request.

{"success":true}

Option 2: Chrome App (Postman)

If you are uncomfortable with the command line, you can use a Google Chrome extension app, like Postman, to achieve the same results. Here's how:

  1. Open Google Chrome. If you do not have Google Chrome, download it from https://www.google.com/chrome
  2. In Chrome, download the Postman App.
  3. Open the Postman app in Chrome.
  4. Where it says "Enter request URL here," put

    https://api.yottaa.com/sites/***Site_ID***/flush_cache

    (inserting your Site ID from above, as appropriate)
  5. Click the dropdown that says  and select "PUT"
  6. Click 
  7. In the "URL Parameter Key" field that appears, put

    user_id

  8. In "Value" on that same line, paste in the Yottaa User ID that we found above.
  9. A new "URL Parameter Key" field will have opened up. Put in

    profile_id

  10. In the "Value" on that same line, paste in the Yottaa Profile ID we found above.
  11. Click 
  12. In the "Headers" field that appears, put in Yottaa-API-KEY
  13. In the "Value" field next to it, past your Yottaa API Key.
  14. This is how the Postman screen should look:
    (note that the "user_id=***User_ID***" part in the URL is automatically added by Postman)
  15. If everything looks correct, click the blue "Send" button. You will receive the following response if the API server properly receives the request:

Once that finishes loading, you should see a success message; this message indicates that the purge request has been successfully initiated -- it may take up to 10 minutes for the cache purge to propagate.

Purging cache for specific URL

Option 1: Command Line (cURL)

Unix:

The following command is meant to be used in a Unix based operating system. Input the user ID, profile ID, site ID, and API key in their respective spaces marked by "***" in the following curl command.

curl -kH "YOTTAA-API-KEY: ***API_KEY***" --data '[{"domain": "www.example.com", "condition":"/path/to/object.png", "name":"URI","content_type":"png"}]' "https://api.yottaa.com/sites/***Site_ID***/purge_cache?user_id=***User_ID***&profile_id=***Profile_ID***"

The information passed into the “--data” section of the command is of the specific object you are trying to purge. This may not have the same domain as your Site ID domain if it’s being hosted from a third party or a CDN. The information you should be putting in should be of your origin source, as in pre-Yottaa optimizations. For example, the domain information should never be something like cdn-us-ec.yottaa.net as that is the Yottaa version of your webpage. You need the information from which cdn-us-ec.yottaa.net is caching and purge that object. You are allowed to purge up to 15 objects in one request. To add additional objects, add the information into the --data array[]. Each object is incased in {} separated by commas. You will receive the following response if the API server properly receives the request.

{"success":true}

Windows:

The curl command is not natively available for Windows operating system. To get around this, you will need to download the curl.exe from the following site. Make sure to click on the download in the Packages section and NOT the Source Archives section.

http://curl.haxx.se/download.html

After downloading and unzipping the package to a directory of your choice, you should have a curl.exe file. Open a command prompt and navigate to the curl.exe file. Input the user ID, profile ID, site ID, and API key in their respective spaces marked by "***" in the following curl command.

curl -kH "YOTTAA-API-KEY: ***API_KEY***" --data "[{\"domain\": \"www.example.com\", \"condition\":\"/path/to/object.png\", \"name\":\"URI\",\"content_type\":\"png\"}]" "https://api.yottaa.com/sites/***Site_ID***/purge_cache?user_id=***User_ID***&profile_id=***Profile_ID***"

Please note that for Windows, most special characters passes into the “--data” section, needs to be escaped. In the example above, the double quotes were escaped with a backslash. The information passed into the “--data” section of the command is of the specific object you are trying to purge. This may not have the same domain as your Site ID domain if it’s being hosted from a third party or a CDN. The information you should be putting in should be of your origin source, as in pre-Yottaa optimizations. For example, the domain information should never be something like cdn-us-ec.yottaa.net as that is the Yottaa version of your webpage. You need the information from which cdn-us-ec.yottaa.net is caching and purge that object. You are allowed to purge up to 15 objects in one request. To add additional objects, add the information into the --data array[]. Each object is incased in {} separated by commas. You will receive the following response if the API server properly receives the request.

{"success":true}

Option 2: Chrome App (Postman)

If you are uncomfortable with the command line, you can use a Google Chrome extension app, like Postman, to achieve the same results. Here's how:

  1. Open Google Chrome. If you do not have Google Chrome, download it from https://www.google.com/chrome/
  2. In Chrome, download the Postman
  3. Open the Postman app in Chrome.
  4. Where it says "Enter request URL here", put

    https://api.yottaa.com/sites/***Site_ID***/purge_cache

    where ***Site_ID*** is your site ID obtained prior.
  5. Click the dropdown that says "Get"  and select "POST"
  6. Click "Params" 
  7. In the "URL Parameter Key" field that appears, put

    user_id

  8. In "Value" on that same line, paste in the Yottaa User ID that we found above.
  9. A new "URL Parameter Key" field will have opened up. Put in

    profile_id

  10. In the "Value" on that same line, paste in the Yottaa Profile ID we found above.
  11. Click "Headers" 
  12. In the "Header" field that appears, put in

    Yottaa-API-KEY

  13. In the "Value" field next to it, paste your Yottaa API Key.
  14. A new "Header" field will have opened up. Put in

    Content-Type

  15. In the "Value" on that same line, put in

    application/x-www-form-urlencoded

  16. Click on the “Body” tab and select the “raw” radius button. In the text field provided, enter the following text substituting your domain, condition, and content_type as appropriate. For more information on what is the appropriate domain, condition, and content_type to put in, please reference the command line instructions provided above regarding the “--data” section.


  17. This is how the Postman screen should look like with the Headers tab selected:
    (note that the "user_id=***User_ID***" part in the URL is automatically added by Postman)

And with the Body tab selected:



If everything looks correct, click the blue "Send" button. You will receive the following response if the API server properly receives the request. 

Troubleshooting

A common response when trying to use the purge_cache API is as follows:

{"error_response":{"name":"Unknown API call","description":"route error"}

This is most likely due to the data being passed in incorrectly. For Windows using command line, make sure the special characters are properly escaped and try again. For Postman, make sure to include “Content-Type” with the value of “application/x-www-form-urlencoded” in the headers tab and try again.

Please note: This feature is not available for all subscription levels. Please contact support@yottaa.com if you believe you should have access and do not.

Have more questions? Submit a request

Comments

Powered by Zendesk