Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. @future (callout=true)
  2. global static void Getfields(String JIRA_Key) {
  3.  
  4. //Construct HTTP request and response
  5. HttpRequest req = new HttpRequest();
  6. HttpResponse res = new HttpResponse();
  7. Http http = new Http();
  8.  
  9. //Modify these variables:
  10. String username = 'admin';
  11. String password = 'xxx';
  12. String jiraURL = 'https://mysfjira.atlassian.net/';
  13.  
  14. //Construct Authorization and Content header
  15. Blob headerValue = Blob.valueOf(username+':'+password);
  16. String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
  17. req.setHeader('Authorization', authorizationHeader);
  18. req.setHeader('Content-Type','application/json');
  19.  
  20. String endpoint = jiraURL+'/rest/api/2/issue/'+JIRA_Key;
  21.  
  22. req.setMethod('GET');
  23. req.setEndpoint(endpoint);
  24. res = http.send(req);
  25.  
  26. System.debug('Serialization :::' +res.getBody());
  27.  
  28. Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
  29.  
  30. System.debug('Deserialization :::' +m);
  31.  
  32. //mapping the fields with case object fields
  33.  
  34. List<Case> casestoUPsert = new List<Case>();
  35.  
  36.  
  37. for(Map<String, Case> c : m){
  38.  
  39.  
  40. Case cas = new Case();
  41. cas.Id = c.id;
  42. cas.JIRA_Key__c = c.key;
  43. cas.Status = c.Status;
  44. cas.Origin = c.Priority;
  45.  
  46. casestoUPsert.add(cas);
  47.  
  48. }
  49. if(casesToUpsert.size()>0){
  50. Database.upsert(casestoUpsert,false) ;
  51. }
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement