In my project, whenever an API is called it gets cached in Akamai. But when a client changes something in the database through UI. We need to invalidate cached API's response in AKAMAI and fill it with the new fresh json data. I found some link on the internet : akamai-purging but I am not able to understand what is cp-code in this link they are talking about?
Here is my sample code which is giving: 405 Not Allowed
Code:
public static void main(String[] args) throws IOException, RequestSigningException {
URL url = new URL("https://xxx-host-name-/scripts.4535eaf743502b25ba3a.js");
HttpTransport HTTP_TRANSPORT = new ApacheHttpTransport();
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
AkamaiPostData postData = new AkamaiPostData();
postData.setHostname(AkamaiConstants.SITE_HOST_NAME);
Gson gson = new Gson();
String postDataJSON = gson.toJson(postData);
byte[] contentBytes = postDataJSON.getBytes();
HttpContent content = new ByteArrayContent("application/json", contentBytes);
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
HttpHeaders headers = request.getHeaders();
headers.set("Host", "xxx-host-name-");
ClientCredential credential = new DefaultCredential(AkamaiConstants.CLIENT_TOKEN, AkamaiConstants.ACCESS_TOKEN, AkamaiConstants.CLIENT_SECRET);
RequestSigner signer = new EdgeGridV1Signer(Collections.EMPTY_LIST, 1024 * 2);
HttpRequest signedRequest = signer.sign(request, credential);
HttpResponse response = signedRequest.execute();
String result = response.parseAsString();
System.out.println("result::" + result);
}