I'm recently have a task on integration with JIRA to Salesforce.i'm successfully getting the JIRA issues in JSON and deserialize the data but when mapping the JIRA issue fields with Salesforce Case fields i'm facing some pblms.
In JSON reponse different parent fields have different child fields have so mapping.i'mdirectly calling the required fields may that's the problem so anyone help me to Correct mapping process.
this is my code :
global with sharing class Jira {
@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) ;
}
}
}
Deserialization ::: {expand=renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations, fields={aggregateprogress={progress=0, total=0}, aggregatetimeestimate=null, aggregatetimeoriginalestimate=null, aggregatetimespent=null, assignee=null, attachment=(), comment={comments=(), maxResults=0, startAt=0, total=0}, components=(), created=2017-03-29T17:01:25.572+0530, creator={active=true, avatarUrls=
Thanks In Advance, sfdev