I am getting the below error when trying to call the HTTP POST
using the Apex
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://ap5.salesforce.com/services/oauth2/token');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/x-www-form-urlencoded');
request.setHeader('client_id','3MVG9d8..z.hDcPJZPXXXXXXXXXXXXXXXXXXX');
request.setHeader('client_secret','XXXXXXXXXXXXXXXXXX');
request.setHeader('username','XXXXXXXXXXXXXXXXXX');
request.setHeader('password','XXXXXXXXXXXXXXXXXXXXXX');
request.setHeader('grant_type','password');
request.setHeader('callbackURL','https://ap5.salesforce.com/oauthcallback.html');
request.setBody('');
HttpResponse response = http.send(request);
System.debug('Response :: '+response.getBody());
And I get the error message.
Response :: {"error":"unsupported_grant_type","error_description":"grant type not supported"}
I am able to call successfully using REST/POSTMAN client and getting the access_token.
[apexrest]
tag is for when you are writing anApexClass
that will serve as a@RestResource
, which does not appear to be the case here. – Adrian Larson♦ May 4 '17 at 16:10