Guest User

Untitled

a guest
Oct 2nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class HttpCalloutJob {
  2.  
  3. public final String consumerKey = '****';
  4. public final String consumerSecret = '****';
  5. public final String username = '****@nihon.com';
  6. public final String password = 'MySfPassword****';
  7. public final String reqbody = 'grant_type=password&client_id='+consumerKey+'&client_secret='+consumerSecret+'&username='+username+'&password='+password;
  8.  
  9. public void getCalloutResponseContents() {
  10.  
  11.  
  12. Http h = new Http();
  13. HttpRequest req = new HttpRequest();
  14.  
  15. req.setBody(reqbody);
  16. req.setMethod('GET');
  17. req.setEndpoint('https://***.lightning.force.com/services/oauth2/token');
  18.  
  19. HttpResponse res = h.send(req);
  20.  
  21. OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
  22.  
  23. System.debug('Body: ' + res.getBody());
  24.  
  25. if(objAuthenticationInfo.access_token!=null){
  26. Http h1 = new Http();
  27. HttpRequest req1 = new HttpRequest();
  28. req1.setHeader('Authorization','Bearer '+objAuthenticationInfo.access_token);
  29. req1.setHeader('Content-Type','application/json');
  30. req1.setHeader('accept','application/json');
  31.  
  32. req1.setHeader(???); //I don't know, what I need to put inside
  33. req1.setMethod('GET');
  34. req1.setEndpoint('https://***.lightning.force.com/services/apexrest/jobShow');
  35. HttpResponse res1 = h1.send(req1);
  36. System.debug('RESPONSE_BODY '+res1.getbody());
  37. }
  38. }
  39.  
  40. public class OAuth2{
  41. public String id{get;set;}
  42. public String issued_at{get;set;}
  43. public String instance_url{get;set;}
  44. public String signature{get;set;}
  45. public String access_token{get;set;}
  46. }
  47. }
Add Comment
Please, Sign In to add comment