You need to sign in to do that
Don't have an account?
Erik Yeary
404 Cannot POST
I'm doing an API Callout to an external REST endpoint from Apex. The endpoint is configured for GET and my code reflects that. For some reason, I am getting a "404: Not Found: Cannot POST /cancelAppointment". I'm confused because my request is clearly designated as a GET.
The site is correctly added to my remote site settings. Also - if I run the same request from Insomnia/Postman, it works fine.
My code:
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://ourwebsite.com/cancelAppointment');
request.setTimeout(20000);
request.setMethod('GET');
request.setHeader('Content-Type', 'text');
request.setHeader('Authorization', 'JWT ' + token); //token is a JWT
request.setBody(getJSONBody()); //this is confirmed to work correctly
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200)
{
System.debug(response.getBody());
}
else
{
System.debug(response.getStatusCode() + ': ' + response.getStatus();
System.debug(response.getBody());
}
The site is correctly added to my remote site settings. Also - if I run the same request from Insomnia/Postman, it works fine.
My code:
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://ourwebsite.com/cancelAppointment');
request.setTimeout(20000);
request.setMethod('GET');
request.setHeader('Content-Type', 'text');
request.setHeader('Authorization', 'JWT ' + token); //token is a JWT
request.setBody(getJSONBody()); //this is confirmed to work correctly
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200)
{
System.debug(response.getBody());
}
else
{
System.debug(response.getStatusCode() + ': ' + response.getStatus();
System.debug(response.getBody());
}
This might help you.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Could it be that the web server that you are calling is interpreting the method as POST because you are passing a body. GET calls don't usually contain body at all but everything necessary is included in the query string in the URL.
Regards,
iRK