Manage Fastly VCL snippets using the API

Delete a snippet

1. Save Fastly service credentials as bash environment variables
export FASTLY_SERVICE_ID=<Service ID>
export FASTLY_API_TOKEN=<API Token>

2. Check active VCL version
curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/active

3. Save active version number returned in the “number” key
export FASTLY_VERSION_ACTIVE=<version>

4. Clone active VCL version and all snippets
curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_VERSION_ACTIVE/clone -X PUT

5. Save the new version number returned in the “number” key
export FASTLY_EDIT_VERSION=<Version>

6. Delete an individual VCL snippet
curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/snippet/<snippet_name> -X DELETE
Note: name of snippet created from admin UI is prefixed with “magentomodule_” in Fastly. For eg. addForwardSlash in admin will be magentomodule_addForwardSlash in Fastly.
To list all regular VCL snippets: curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/snippet

7. Validate custom VCL snippets
curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/validate

8. Activate VCL snippets
curl -H “Fastly-Key: $FASTLY_API_TOKEN” https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/activate -X PUT

Leave a Reply