0

Am Integrating salesforce with Jira.I want to save the Jira Id in salesforce in which i created a custom field in CaseObject.Can you please provide me solution for it...??

Here is my code..

global class JiraIntegration{
   @future(callout=true)
    public static void CreateIssueinJIra(String objectType,String projectKey,String issueType,string summary,string description){
    new JiraIntegration(objectType,id,projectKey,issueType,summary,description);
    }

      public string summary;
      public string description;

         public JiraIntegration(){
             }
        //Change values in this class according to you JIRA/Salesforce coordinates.
         public String baseUrl = 'https://JIraURl/rest/api/2/issue/'; // Base URL of your JIRA instance
         public String username = 'abc';  // JIRA username
         public String password = 'xxx'; // JIRA password

     // Constructs Basic Http Authentication header from provided credentials
        public String authHeader(){
        Blob headerValue = Blob.valueOf(username+':'+password);
        return 'Basic ' + EncodingUtil.base64Encode(headerValue);
    }
          public JiraIntegration(String objectType,String projectKey,String issueType,string summary,string description){   
          HttpRequest req = new HttpRequest();
          Http http = new Http();
          req.setMethod('GET');

    //Set HTTPRequest header properties
        req.setHeader('Accept', 'application/json');
        req.setHeader('Content-Type','application/json');
        Blob headerValue = Blob.valueOf(username+':'+password);
        req.setHeader('Authorization','Basic '+ EncodingUtil.base64Encode(headerValue));
        req.setEndpoint(baseUrl);
        String CreateIssueinJIraJson= '{"fields": {"project":{"key": "ab"},"summary":"'+ +'","description":"'+ +'" ,"issuetype":{"name": "Bug"}}}';
       String JSONData = JSON.serializePretty(CreateIssueinJIraJson);   
       req.setBody(CreateIssueinJIraJson);


       system.debug('after response....'+CreateIssueinJIra);
    try{
            //Execute web service call here      
    HTTPResponse res = http.send(req);  
    String ResponseJsonString = res.getBody();       
        }              
         catch(System.CalloutException e){
         System.debug('Callout error: '+ e);

         }  
    }
}
3
  • Can you please detail what you have done until now? Meanwhile, you can take a look at a relate question salesforce.stackexchange.com/questions/38541
    – Jarvis
    Dec 31, 2015 at 5:56
  • HI Bennie I have just created an Issue in jira,Now i have to save the jira id in Case Object.Please help me out.. Here is my Code
    – Uday
    Dec 31, 2015 at 7:49
  • Bennie I posted my code In Question itself . Please help me out..!!
    – Uday
    Dec 31, 2015 at 8:02

1 Answer 1

3

Looking at the JIRA API call, the JIRA key (e.g. TST-24) is returned in the response:

{
    "id": "10000",
    "key": "TST-24",
    "self": "http://www.example.com/jira/rest/api/2/issue/10000"
}

You can grab that and then update the Case providing you have passed in some way of identifying the Case. This code assumes you've passed in the Case ID in a variable called caseId:

Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
String jiraKey = (String) m.get('key');
update new Case(Id = caseId, JiraKey__c = jiraKey);
0

Not the answer you're looking for? Browse other questions tagged .