I am trying to connect org using rest api. I am getting error:[Status=Bad Request, StatusCode=400]
.I am not getting access token back
Here is my Code:
<apex:page controller="SendWaveUsingRESTAPI">
<apex:form >
<apex:pageBlock >
<apex:actionFunction action="{!ReturnAccessToken}" name="wavescript" immediate="true" Id="WaveId"/>
<input id="clickMe" type="button" value="Connect" onclick="wavescript();"/>
</apex:pageBlock>
</apex:form>
</apex:page>
class:
public class SendWaveUsingRESTAPI {
private final String clientId = 'XXXX';
private final String clientSecret = 'XXXXXX';
private final String username = 'XXXX';
private final String password = 'XXXXX';
public class deserializeResponse
{
public String id;
public String access_token;
}
public void ReturnAccessToken()
{
String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint('https://XXXXXXX.my.salesforce.com/services/oauth2/token');
HttpResponse res = h.send(req);
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
system.debug('@@@@access_token@@'+resp1 );
}
}
in the resp1 it is coming as null.
res.getBody()
also returning null?