I'd like to apologize in advance as I'm quite new to writing APEX Classes / Triggers. I've followed a tutoriel of which the aim is to POST a comment to an external system, in this case it's Jira.
I have a few problems, first of all I'm thinking my IssueId should be something I define as a variable that I'd like to set from the flow that triggers the apex class. How do you think I should go about doing this ?
I'd also like to set the Body as a variable set in the triggering flow.
I suppose I'd have to write methods to do this sort of thing ?
Finally it seems this class is not invocable due to the datatype of the method. Perhaps writing new methods to support above requirements would fix my issue ?
I'd love to have a few pointers to help me go about this.
public class JIRAwebserviceCallout {
public static void addCommentToJiraIssue(String IssueId){
try{
Jira_Credentials__c jiraCreds = [Select id, Jira_API_Token__c, Jira_Password__c, Jira_URL__c, Jira_UserName__c from Jira_Credentials__c Limit 1];
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
Blob headerValue = Blob.valueOf(jiraCreds.Jira_UserName__c + ':' + jiraCreds.Jira_API_Token__c);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('content-type','application/json');
req.setHeader('accept', 'application/json');
req.setMethod('POST');
req.setEndpoint(jiraCreds.Jira_URL__c + '/rest/api/2/issue/' + IssueId + '/comment');
req.setBody('{"body": "This is a test comment" }');
res = http.send(req);
System.debug('ResponseBody::'+res.getBody());
}
catch(Exception ex){
System.debug('ERROR:' + ex.getMessage());
}
}
}