Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For this example, I will be building off this page, “Running Scripts Via REST”.

  1. Import the curl script into Postman by following these instructions.

  2. In the right-hand side of Postman, click on the “</>” symbol to see the code converter.

  3. Select the language you would like to convert. “Java - Unirest” is the easiest because it parses the headers in a way that is easiest to refactor into SIL code.

    Image Modified
  4. Create headers based on the Java code. The following copied from the Java code…

    Code Block
    .header("Accept", "application/json")
    .header("Content-Type", "application/json")
    .header("Authorization", "Basic PFVTRVJOQU1FOlBBU1NXT1JEPg==")

    …can be converted into:

    Code Block
    HttpRequest request;
    request.headers += httpCreateHeader("Accept", "application/json");
    request.headers += httpCreateHeader("Content-Type", "application/json");
    request.headers += httpCreateHeader("Authorization", "Basic PFVTRVJOQU1FOlBBU1NXT1JEPg==");
  5. Now set a string variable using the body. You should be able to paste the string without modification.

    Code Block
    string payload = "{ \n  \"source\": {\n    \"type\": \"FILE\", \"code\": \"<PATH/TO/FILE.SIL>\"\n  },\n    \"args\": [<\"ARGUMENTS\", \"FOR\", \"ARGV\", \"GO HERE\">]\n  }";
  6. Lastly, convert the Java post() method to httpPost():

    Code Block
    httpPost("http://localhost:8080/rest/keplerrominfo/refapp/latest/async-script/runScript", request, payload);

Final Script

Now that we have all the basic building blocks for a script, put them all together and add some error message handling at the end of the script. If you would like to change up the values passed by the payload, see this documentation on working with JSON.

Code Block
string payload = "{ \n  \"source\": {\n    \"type\": \"FILE\", \"code\": \"createIssue.sil\"\n  },\n    \"args\": [\"EX\", \"\", \"Task\", \"summary goes here\"]\n  }";

HttpRequest request;
request.headers += httpCreateHeader("Accept", "application/json");
request.headers += httpCreateHeader("Content-Type", "application/json");
request.headers += httpCreateHeader("Authorization", "Basic PFVTRVJOQU1FOlBBU1NXT1JEPg==");

string value = httpPost("http://localhost:8080/rest/keplerrominfo/refapp/latest/async-script/runScript", request, payload);

runnerLog(value);

number statusCode = httpGetStatusCode();
if (statusCode >= 200 && statusCode < 300) {
    runnerLog("SUCCESS");
}
else {
    string msg = trim(statusCode) + ":" + httpGetErrorMessage() + ":" + httpGetReasonPhrase();
    runnerLog(msg);
}

Additional Help

Need help implementing this script? Talk to me directly to me by clicking on the bot on bottom of our anovaapps.com page. 

Filter by label (Content by label)
page
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@135a7
showSpacefalse
sortmodified
showSpacetypefalsepage
reversetruetype
labelskb-how-to-article
cqllabel = "kb-how-to-article" and type = "page" and space = "PKB"labelskb-how-to-article
Page Properties
hiddentrue

Related issues