Super Contributor.. Super Contributor..
Super Contributor..

Java script with REST request to external system (Jira)


Sending system: SM
Receiving system: Atlassian Jira

I am building a REST request from SM to the external system Jira. The goal is to create a record in Jira.
I have managed to create the record using curl in a batch file:

Batch file contents:
curl -u "username:pass" -X "POST" -H "Content-Type:application/json" -d @Json.txt

I can run the batch file from the command line. It will open a session to the remote Jira server and open a new Jira record. The -d @Json.txt will read the json.txt file and push that request to the Jira server

json.txt contents:






            "key": "Project 344"


        "summary": "LB dosent write to Event Log",

        "description": "Logging is not configured for the LB server",



            "name": "Bug"





Now the question: have anyone done something similar but using java script in SM instead?
(I know this is build in when using SMAX but we are using SMA-SM)

Labels (4)
1 Reply
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Java script with REST request to external system (Jira)

It's somewhat complex to implement, but once you've done it once it's not that difficult.

You have to create the Json object in JavaScript like this:

var crearJira = {
"fields": {
"project": {
"key": "Project 344"
"summary": probsummaryFile.brief_description,
"description": lib.stanumUtils.array2text(probsummaryFile.action),



You then convert it into a format that doHTTPrequest can use:

var request = system.library.JSON2.toJSON(crearJira);

Then you call the rest Service:

var res = doHTTPRequest("POST", URL, arrHeaders, request, 15, 15, 15);
JSNres = system.library.JSON3.parse(res);
print("[Jira] Jira id: " + + " key: " + JSNres.key);





The arrHeaders object can be a bit tricky to construct, I wrote a function for that (you'll need to write your own getBase64Encode function) that accepts user and password to do basic authentication:


function getRequestHeaderAuth(User, Password) {

var authHeader = new Header(); = "Authorization";
authHeader.value = "Basic " + system.library.Utilities.getBase64Encode(User + ":" + Password);

var typeHeader = new Header(); = "Content-Type";
typeHeader.value = "application/json; charset=utf-8";

var arrHeaders = new Array();

return arrHeaders;



The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.