LOG IN SIGN UP
Documentation

Authenticating URL purge requests via API

Fastly's URL purge feature allows you to purge individual URLs on your website. By default, authentication is not required to purge a URL with the Fastly API, but you can enable API key authentication in the Fastly web interface by adding a header or by using custom VCL.

Enabling authentication in the Fastly web interface

You can enable API key authentication for URL purge requests by adding a header and optionally attaching a condition in the Fastly web interface.

Adding the header

  1. Log in to the Fastly web interface and click the Configure link.
  2. From the service menu, select the appropriate service.
  3. Click the Edit configuration button and then select Clone active. The service version page appears.
  4. Click the Content tab. The Content page appears.

    the Content page

  5. Click the Create header button. The Create a new header window appears.

    Create a new header window

  6. Fill out the Create a new header fields as follows:

    • From the Type menu, select Request, and from the Action menu, select Set.
    • In the Destination field, type http.Fastly-Purge-Requires-Auth.
    • In the Source field, type "1".
    • From the Ignore if set menu, select No.
    • In the Priority field, type 10.
    • In the Description field, type the name of your header rule (for example, Fastly Purge).
  7. Click the Create button.

Attaching a condition

Attaching the following condition is optional. Without the condition, the header you just created will be added to all requests. With the condition, the header will be added to purge requests only.

  1. On the Content page, click the Attach a condition link to the right of your new header. The Create a new request condition window appears.

    Create a new request condition window

  2. Fill out the Create a new request condition fields as follows:

    • From the Type menu, select Request.
    • In the Name field, type a descriptive name for the new condition (for example, Purge).
    • In the Apply if field, type req.request == "FASTLYPURGE".
  3. Click the Save and apply to button.

  4. Click the Activate button to deploy your configuration changes.

Enabling authentication with custom VCL

If you'd rather enable API key authentication for URL purge requests using custom VCL, add the following to your VCL file:

if (req.request == "FASTLYPURGE") {
  set req.http.Fastly-Purge-Requires-Auth = "1";
}

Purging URLs with an API key

After you've enabled API key authentication for URL purge requests, you'll need to provide your API key in the URL purge API request:

curl -X PURGE -H Fastly-Key:$FASTLY_KEY https://www.example.com/

which would return this response:

{"status": "ok", "id": "1234567890"}

Back to Top