JIRA REST Integration problem

Vejdis
Tera Expert

Hello!

I'm trying to create an API integration via REST to JIRA. I have been following the JIRA api documentation (https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples).

I have made a Rest message that has the following body 

{
    "fields": {
       "project":
       {
          "key": "ST"
       },
       "summary": "${short_description}",
 "description": "${description}",
       "issuetype": {
          "name": "Task"
       }    

   }
}

 

The variables $description and $short_description are being populated by running a business rule that runs

            var r = new sn_ws.RESTMessageV2('x_zeab_ida_infront.Ida Infront Message', 'Create Issue');
            r.setStringParameterNoEscape('description', current.getValue('description'));
            r.setStringParameterNoEscape('short_description', current.getValue('short_description'));
 
            var response = r.executeAsync();
            response.waitForResponse(10);
            var responseBody = response.getBody();
            var httpStatus = response.getStatusCode();
            gs.info(httpStatus);
            gs.info(responseBody);

When I try this with hardcoded description it works and a task is created in my jira instance. However when I run it with a dynamic description I get this error from JIRA:

{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}

 

The short_description works as intended and if I replace current.getValue('description')) with current.getValue('short_description') the ticket gets created. 

I have tried with using toString(); etc on the description variable anything I can come up with to make sure it is a string. But the result is always the same. If I take the data from the description field in my Service Now incident, I get this error. 

Have anyone created a similar integration? Or does anyone have any idea on what the issue can be?

1 ACCEPTED SOLUTION

Vejdis
Tera Expert

To anyone stumbling upon this in the future. The issue came from how the JSON body was generated from the ${description}. I simply added a .trim() at the end and it works

View solution in original post

4 REPLIES 4

Mathieu Lepoutr
Mega Guru

Hi Vejdis

I'm working as a pre-sales engineer with Exalate.

Exalate was designed with exactly these types of use-cases in mind, you could say that it is our "bread and butter".

One of Exalate's features, apart from syncing tickets bi-directionally, is having access to an HttpClient, this is very useful to access numerous amounts of data, which then can be syncronized to Jira.

The ticket will out-of-the-box be fully bi-directionally syncronized, which means, if a field gets updated on either side, it will automatically update on the other side, you can change this to make it uni-directional if you so please.

Exalate is easy and straightforward to set-up and you can control exactly which data you want to send and/or receive. 

If you would like to see a customized demo of the product, please book a slot.

Cheers

Eric Smith
Tera Expert

Vejdis, hi! My team and I quite often connect the two but using a connector. And we're happy with the end result. We sync the two and keep them up to date constantly.

Thanks for the info but I'm quite limited in the connectors 3rd party apps we can use hence, I must write the api integration myself

Vejdis
Tera Expert

To anyone stumbling upon this in the future. The issue came from how the JSON body was generated from the ${description}. I simply added a .trim() at the end and it works