2

Some REST endpoints do support the use of _HttpMethod override parameter:

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod. In the PATCH example, you can replace the PostMethod line with one that doesn't use override:

https://www.salesforce.com/us/developer/docs/api_rest/Content/dome_update_fields.htm

I tried this as the endpoint:

https://pod.salesforce.com/services/data/v32.0/tooling?_HttpMethod=POST

which returns a response that indicates the HTTP method override isn't happening:

<title>Error 405 GET not supported</title>
</head>
<body><h2>HTTP ERROR 405</h2>
<p>Problem accessing /services/Soap/m/32.0. Reason:
<pre>GET not supported</pre></p>
<hr /><i><small>Powered by Jetty://</small></i><br/>  

Could be a stupid question because I haven't even thought about where the request body goes yet.

Is there any way to invoke a Salesforce SOAP API using a GET method?

2

Is there any way to invoke a Salesforce SOAP API using a GET method?

No, I don't believe so. The SOAP API requests all use the POST verb. There is nothing stopping you making the required HttpRequests to the tooling API if you don't want to use WSDL2Apex (or its variants).

E.g. extract for calling the Tooling API SOAP query method. (Parts to do the XML processing are missing, but you should get the overall idea).

    public toolingSoapSforceCom.QueryResult query_Http(String queryString) {
        DOM.Document doc = new DOM.Document();
        DOM.XmlNode body = populateDoc(doc);
        DOM.XmlNode methodNode = body.addChildElement('query', 'urn:tooling.soap.sforce.com', '');          
        toolingSoapSforceCom.query_element request_x = new toolingSoapSforceCom.query_element(queryString);
        request_x.populateXmlNode(methodNode);

        HttpRequest req = new HttpRequest();
        req.setEndpoint(endpoint_x);
        req.setMethod('POST');
        req.setHeader('Content-Type', 'text/xml; charset=UTF-8');
        req.setHeader('SOAPAction', 'blank');
        req.setBodyDocument(doc);

        Http http = new Http();
        HTTPResponse res = http.send(req);

        Dom.Document responseDoc = res.getBodyDocument();
        Dom.XmlNode rootNode = responseDoc.getRootElement();
        Dom.XmlNode bodyNode = rootNode.getChildElement('Body','http://schemas.xmlsoap.org/soap/envelope/');
        Dom.XmlNode queryResponseNode = bodyNode.getChildElement('queryResponse', 'urn:tooling.soap.sforce.com');

        toolingSoapSforceCom.queryResponse_element response_x = new toolingSoapSforceCom.queryResponse_element(queryResponseNode);
        return response_x.result;
    }

I guess you could wrap the required services in your own Apex RESTful service to provide the required GET support. Not very efficient, but it would work. Just be careful someone doesn't index the GET request with a search engine or you could create a new Apex class with every request. Sounds a bit risky using GET for anything with side effects now I've typed it out.

1

I was not able to use the _httpMethod=PATCH with a project I was working on.

What I did was:

setHeader('X-HTTP-Method-Override','PATCH');

Not sure if this example will hep with a get or not but worth a shot.

try

setHeader('X-HTTP-Method-Override','POST');
  • Very shrewd, thank you. Gave this a shot but 405 (GET not supported). Worth a try! – bigassforce Dec 21 '14 at 3:30
  • @bigassforce - Oh well - worth a shot. I will leave the answer here in case someone else hits it for other services other than Salesforce REST. I know it worked on Google Drive API which did not accept _HTTPMethod=PATCH – Eric Dec 21 '14 at 3:43
  • @bigassforce - What if you set the method to POST, and set the override to GET? - Not sure if that will get you what you want since GET seems to not be supported but...... – Eric Dec 21 '14 at 5:03
  • Unfortunately the HTTP client is a red-haired stepchild that doesn't do POST verb :( – bigassforce Dec 21 '14 at 5:04
  • @bigassforce - Not sure where the issue is, Using the Endpoint you have in the question AND a test PATCH, it worked fine. Why are you trying to use GET? Is it because the environment you are using will not allow anything other than GET? What if you use the _HttpMethod=PATCH? – Eric Dec 21 '14 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.