Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final String AUTH_URL = 'https://test.salesforce.com/services/oauth2/token';
- public static final String CONSUMER_KEY = '3MVG97wqanbUM37IrVAYa3ZeAtHO0PIQOmIJOQPSG3C7ZlKqV6qQ28LOLPkefh_JEfzMwrWX2JVJ.k0o6TgEr';
- public static final String CONSUMER_SECRET = '5259521906564034481';
- public static final String API_USERNAME = 'admin@unisource.com.salesiq';
- public static final String API_PASSWORD = 'P@ssw0rd1';
- String reqString = String.format('grant_type=password&client_id={0}&client_secret={1}&username={2}&password={3}',
- new String[] {EncodingUtil.urlEncode(CONSUMER_KEY, 'UTF-16'),
- EncodingUtil.urlEncode(CONSUMER_SECRET, 'UTF-16'),
- EncodingUtil.urlEncode(API_USERNAME, 'UTF-16'),
- EncodingUtil.urlEncode(API_PASSWORD, 'UTF-16')});
- System.debug(reqString);
- HttpRequest authRequest = new HttpRequest();
- authRequest.setMethod('POST');
- authRequest.setHeader('Content-Type', 'application/x-www-form-urlencoded');
- authRequest.setBody(reqString);
- authRequest.setEndpoint(AUTH_URL);
- Http http = new Http();
- HttpResponse authResponse = http.send(authRequest);
- System.debug(authResponse.getBody());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement