Running Scripts Via REST

In certain cases, it is necessary to run SIL Scripts from an outside source. 

Background

In order to run SIL Scripts via REST, use the SIL Common REST Service.

Basic Steps

When creating scripts for use with REST, follow these steps:

  1. Create the script with hard-coded values and make sure it works the way you want it to.

  2. Replace the hard-coded values with variables that accept arguments (the argv variable) when run from an outside source.

  3. (optional) Test the script using the call() routine. This is an important step to test the script without the complications of a network.

  4. Make modifications to the example curl script to test running the script.

I will break down each step with an example script that uses the createIssue() routine.

Create a Script with Hard-Coded Values

Create a script and hard-code the values for easy implementation. Test that the script works as expected.

string newIssueKey = createIssue(     "DEMO",      "",      "Task",      "Summary goes here" );   if (isNotNull(newIssueKey)){     printInFile("debug.txt", "Issue " + newIssueKey + " was created."); } else {     printInFile("debug.txt", "An issue was not created"); }

Replace the Hard-Coded Values with Variables

In the script below, note how the variables are configured in such a way as to accept arguments from the "argv" variable. We will use argv to pass variables when we run the script from an outside script or REST call.

string project = argv[0]; string parent = argv[1]; string issueType = argv[2]; string summary = argv[3];   string newIssueKey = createIssue(     project,      parent,      issueType,      summary );   if (isNotNull(newIssueKey)){     printInFile("debug.txt", "Issue " + newIssueKey + " was created."); } else {     printInFile("debug.txt", "An issue was not created"); }

Test the Script Using the Call() Routine

In a separate script, run the script using the call() routine. Notice how the number of elements in the array matches the arguments used by argv in the above script. The arguments used should match all elements accessed in the script being called. 

string project = "DEMO"; string parent = ""; string issueType = "Task"; string summary = "summary goes here";     call("", "createIssue.sil", {project, parent, issueType, summary});

 

If everything goes well, you will see something like the following in the “debug.txt” folder under the silprograms folder (remember to click on the “Refresh” button to view changes after the script runs).

Test the Script Using Curl

Below is an example curl script with the parts to be replaced in all capital letters for readability. 


For an example of an working curl script, see the the script below:

 

If everything goes well after running the curl command, you will see something like the following in the “debug.txt” folder under the silprograms folder (again, remember to click on the “Refresh” button to view changes after the script runs).

Test the Script Using a SIL Script

Here is the same call as using curl, but using httpPost() instead.

Additional Help

Need help implementing this script? Talk to me directly to me by clicking on the bot on this page.

Filter by label

There are no items with the selected labels at this time.