Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @future (callout=true)
- global static void Getfields(String JIRA_Key) {
- //Construct HTTP request and response
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- Http http = new Http();
- //Modify these variables:
- String username = 'admin';
- String password = 'xxx';
- String jiraURL = 'https://mysfjira.atlassian.net/';
- //Construct Authorization and Content header
- Blob headerValue = Blob.valueOf(username+':'+password);
- String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- req.setHeader('Content-Type','application/json');
- String endpoint = jiraURL+'/rest/api/2/issue/'+JIRA_Key;
- req.setMethod('GET');
- req.setEndpoint(endpoint);
- res = http.send(req);
- System.debug('Serialization :::' +res.getBody());
- Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
- System.debug('Deserialization :::' +m);
- //mapping the fields with case object fields
- List<Case> casestoUPsert = new List<Case>();
- for(Map<String, Case> c : m){
- Case cas = new Case();
- cas.Id = c.id;
- cas.JIRA_Key__c = c.key;
- cas.Status = c.Status;
- cas.Origin = c.Priority;
- casestoUPsert.add(cas);
- }
- if(casesToUpsert.size()>0){
- Database.upsert(casestoUpsert,false) ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement