Single URL Purge using API

New to Fastly, and I’m attempting to do a single URL purge. According to the documentation, the URL for this is

https://api.fastly.com/purge/{{cached_url}}
Along with the Fastly-Key header.

However, when I attempt to use this, I get a 404 Not Found. But I do get a response of:

{“msg”:“Record not found”,“details”:“Cannot find service”}

I did a purge from the admin console with my Developer Tools open, and I noticed that it appeared to use the following URL for single URL purge:

https://api.fastly.com/service/{{service_id}}/purge_url/{{cached_url}}

When I tried using that URL, I did receive a 200 and the response content was:

{ “status”: “ok”, “id”: “7100146-1770786701-2307239” }

So it appeared to do something. But when I tried to access the cached_url from the CDN, I still received the older version.

What am I doing wrong?

Hey @TomFrey this is the way to do a single URL purge Purging | Fastly Documentation

curl -i -X POST "https://api.fastly.com/purge/www.example.com/path/to/object-to-purge" \
-H "Fastly-Key: YOUR_FASTLY_TOKEN" \
-H "Accept: application/json"

HTTP/2 200
content-type: application/json

I’m wondering if the request you’re testing with is malformed by accident. Can you drop in the curl of the request you’re testing with (with the cached_url redacted if you prefer)?

Thanks for taking the time to respond. I did RTFM :wink: but I’m not using curl. I’m using the postman collection that I downloaded from somewhere on the Fastly site. Postman does allow me to generate the equivalent curl snippet:

curl --location --request POST ‘https://api.fastly.com/purge/PATH_TO_MY_FILE’
–header ‘Host: api.fastly.com
–header ‘Accept: application/json’
–header ‘Fastly-Key: MY_FASTLY_TOKEN’

It looks a little different, but again, I’m using the postman collection from Fastly.

I tried using windows curl with the exact syntax you sent. Still no luck. Here’s the output:

HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Length: 59
content-type: application/json
x-served-by: cache-iad-kcgs7200153

{“msg”:“Record not found”,“details”:“Cannot find service”}

More information. I am able to get the purge_all to work using the Fastly postman collection. So I don’t think the issue is malformed syntax.

For debugging the 404 issue, please try to use that same token to obtain the service details for that service. If that also fails, then the issue is that the token you are trying to use does not have permission to manipulate that service.

If that succeeds, but purging still returns 404, then please confirm that the token was given ‘purge’ permission when it was created.

@kevin.fleming I get a 200 for service details, along with a large JSON response.

Here’s what the admin shows for my API token (with my info whited out):

@kevin.fleming Not sure if you saw my message last week. Do my permissions look good?

Yes, those look sufficient for what you are trying to do. I think at this point you’ll need to create a support ticket to get some more focused attention and debugging than we can offer here.