Am Integrating salesforce with Jira. I want to save the Jira URL in salesforce in which I created a custom field in internalrequest__C. I searched for some documentation from JIRA REST API and when you created a ticket from using POST you will get the response with the URL as an example from the same article:
{
"id": "10000",
"key": "TST-24",
"self": "http://www.example.com/jira/rest/api/2/issue/10000"
}
but when I tried to get the "self" to be displayed in my custom field it always shows empty, IDK if it is something wrong with my code, can someone help me or explain to me how to complete this task?
My code:
public class jira_Insert {
@future(callout = true)
public static void createTicket(String project_value,String summary_value, String description_value
,String issue_type_value){
string username = 'username';
string password = 'password'; //the security token from Atlassian account profile --> Manage your Account-->Security-->API token-->Create and manage API tokens--> Manage your account-->API tokens
String auth_header = 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(username + ':' + password));
String url = 'URL';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Content-Type', 'application/json;charset=utf-8');
req.setHeader('Accept','application/json');
req.setHeader('Authorization', auth_header);
req.setHeader('X-Atlassian-Token', 'nocheck');
req.setMethod('POST');
req.setEndpoint(url);
req.setBody('{ "fields": { "project": { "key": "'+project_value+'" }, "summary": "'+summary_value+'", "issuetype": { "name": "'+issue_type_value+'" }, "description": "'+description_value+'" } }');
try {
HttpResponse res = http.send(req);
system.debug(res);
Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
String jiraSelf = (String) m.get('self');
update new Internal_Request__c (Jira_URL__c = jiraSelf);
} catch (Exception e) {
system.debug('Error: ' + e);
}
}
}
Internal_Request__c
along with URL to update the record.