- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-27-2020
10:59 PM
09-27-2020
10:59 PM
How to generate OAuth token from salesforce Apex class
Please use the below sample code to generate the token using OAuth client ID and secret key.
HttpRequest objReq = new HttpRequest();
string client_key= '94988c5a-6f8e-48ce-8635-f79f0de0bc31';
string client_secret = 'xTpUHqujbYZD5ufNjiS7AUBxVGF5yvn/AC8R/+FxY';
objReq.setEndpoint('https://rest.apisandbox.zuora.com/oauth/token');
objReq.setMethod('POST');
objReq.setHeader('Content-Type', 'application/x-www-form-urlencoded');
objReq.setBody('client_id='+EncodingUtil.urlEncode(client_key,'UTF-8')+'&client_secret='+EncodingUtil.urlEncode(client_secret,'UTF-8')+'&grant_type=client_credentials&undefined=');
//objReq.setBody('client_id=thisisdummyclientkey&client_secret=thisisdummyclientsecret&grant_type=client_credentials&undefined=');
Http objHttp = new Http();
HTTPResponse objRes = objHttp.send(objReq);
system.debug('Token..'+objRes.getBody());
If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √