function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bakul.patelbakul.patel 

HTTP Method 'GET' not allowed. Allowed are POST

Hi,
I am gettig this error on my RestResource class. I have just one method defined with annotation @HttpPost.
When client application calls this rest service, we ensure that it is sending POST request, not GET.

But still Salesforce compalins saying that HTTP Method 'GET' not allowed. Allowed are POST

Has anybody faced this error? any thoughts?

Thanks,
Bakul
salesforce mesalesforce me
Hi check this once...

This is resolved. Either there is a mistake in the REST API cheatsheet  or I just misunderstood it.

 

It indicates the Create/POST endpoint is /sobjects

when in fact it is /sobjects/my_custom_object__c
bakul.patelbakul.patel
Hi,
I had checked that.
But the problem I am facing is not with Salesforce REST APIs. I have my own REST API class where I am facing this problem.
I am just now sure, why salesforce treats a POST request as GET request?

Below is my REST SERVICE class.
@RestResource(urlMapping='/answers/*')
global with sharing class WebServiceForAnswer{
    @HttpPost 
    global static void insertAnswers() {
    	RestRequest req     = RestContext.request;
    	system.debug('request'+req);
        RestResponse res    = RestContext.response;
        processRequest(req, res);
    }
    
    global static void processRequest(RestRequest req, RestResponse res) {
    	
    }
}



Thanks,
Bakul