I'm looking for a way to create an HttpRequest
in Apex using a POST
method. When I do it, I hit this error:
{
"message": "HTTP Method 'POST' not allowed. Allowed are HEAD,GET,PATCH,DELETE",
"errorCode": "METHOD_NOT_ALLOWED"
}
When I try to make a PATCH
request (to update), there's an exception appearing in the developer console:
FATAL_ERROR System.CalloutException: Invalid HTTP method: PATCH
Just to give a quick background, I'm trying to use Salesforce's REST API from inside my Apex class to update an CurrencyType
record. It's working outside Salesforce (using curl
for example).
Thanks.
Best Answer
Here is a working POST example...
Here is a working PATCH example..
Note: The documentation for setMethod does not list 'PATCH' as a method, though it says 'for example', so its unclear if its saying its not supported or the documentation author just missed it out.
Fortunately you can override the Http method as a URL parameter as described here.