0

i created Apex rest service and @HttpPost method , i am able call POST method & got data in request body successfully from workbench. but i had issue with when i try to access from Post man.

i got error with 405 method not allowed.

{
    "errorCode": "METHOD_NOT_ALLOWED",
    "message": "HTTP Method 'GET' not allowed. Allowed are POST"
}

if i change @HttpPost annotation to @HttpGet i am able to call method & access the request data successfully. NOTE: i am accessing Salesforce via Connected App & Oauthflow why only @HttpPost Methods got opposed?

1
  • 1
    That’s working per designed. You can use GET request only if you annotate with @HttpGet and use POST when you annotate with at HttpPost Commented Jun 12, 2020 at 5:42

1 Answer 1

1

405 is for "The request method doesn't have a corresponding Apex method."
The method is correctly declared by @HttpPost annotation. This helps in sending large content via post body instead of the URL. Postman, there is a problem , if it gets 301 or 302 from Salesforce (a redirect directive), it redirects with a GET Method. So in a nutshell, you should test using the interface/device that you are planning to use in Production to access your Apex Rest Service.

1
  • Ran into this when the URL was specified with https://; SF redirected to the secure endpoint, and Postman silently changed it into a GET. Worse, if you have "automatically follow redirects" turned on (the default), it doesn't tell you it was redirected. It's not even reported in the Postman Console. Commented Jul 9, 2020 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .