help needed Getting error while using Rest Client to make SFDC OAuth user password call
Hi,
I am trying to make SFDC Oauth Username password rest api call to get session key, however I keep get error message "error making http request: Bad Request".
I configured the domain name in Admin-> System->HTTP Client as ".salesforce.com"
and created the following end point:
---endpoint code starts -----------------
<#assign url = "https://login.salesforce.com/services/oauth2/token" />
<#assign response = http.client.request("https", "login.salesforce.com", "/services/oauth2/token").body("{ 'grant_type':'password', 'client_id':'parameter', 'client_secret':'parameter', 'username':'parameter', 'password':'parameter' }", "application/x-www-form-urlencoded").post() />
<response>
<#if response.hasError>
<error>${response.error.message}</error>
<error>${response}</error>
<error>${response.error}</error>
<error>${response.status}</error>
<#else>
<content>${response.content}</content>
</#if>
</response>
---endpoint code ends ---------------------------------
I get below response to endpoint:
-------endpoint response start ------------------------
<response>
<error>error making http request: Bad Request</error>
<error>lithium.coreapi.webui.template.models.HttpClientResponseTemplateModel@4a048f3b</error>
<error>lithium.coreapi.webui.template.models.HttpClientResponseTemplateModel$Error@71579073</error>
</response>
-------endpoint response ends -------------------------
The same call works for me in advanced chrome rest client.
Can some one help with issue.
Thanks,
Sachin
It looks like the body of the request is in a JSON format, but you're specifying the enctype as "application/x-www-form-urlencoded".Try changing it to "application/json".
Otherwise, if you need to use "application/x-www-form-urlencoded", change the body to something like this:
Name=Jonathan+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21
See here for more details:
http://en.wikipedia.org/wiki/POST_%28HTTP%29#Use_for_submitting_web_forms