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 .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 .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)

  • 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;