I am trying to use nodeJS request library to issue a POST request to purge content associated with a certain surrogate key via Fastly API. The POST request would look something like this:
POST /service/SU1Z0isxPaozGVKXdv0eY/purge
Content-Type: application/json
Accept: application/json
Fastly-Key: YOUR_FASTLY_TOKEN
Fastly-Soft-Purge: 1
Surrogate-Key: key_1 key_2 key_3
I tried to do this in node.JS two different ways.
The first:
// perform request to purge
request({
method: `POST`,
url: `/service/${fastly_service_id}/purge${surrogateKeyArray[i]}`,
headers: headers,
}, function(err, response, body) {
// url was not valid to purge
if (err) {
console.log("is there an err???")
console.log(err)
}
})
}
I get, Error: Invalid URI: /service/<fastly_Service_id>/purge/<surrogate_key>
I double checked my surrogate key via curl -s -I -H "Fastly-Debug: 1" <URL corresponding to surrogate key> | grep surrogate-key
And it returns the same surrogate-key used in my code.
In the second attempt, I tried:
// perform request to purge
request({
method: `POST /service/${fastly_service_id}/purge${surrogateKeyArray[i]}`,
headers: headers,
}, function(err, response, body) {
// url was not valid to purge
if (err) {
console.log("is there an err???")
console.log(err)
}
})
}
I get the error, Error: options.uri is a required argument