How do I write a REST POST Script in SIL ?

Charlie Score
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 16, 2018

I have the following Google Script that works when executed from a GoogleSheet

function CreateIncident() {

var username = "user";
var password = "Password";
var UserCredentials = "Basic " + Utilities.base64Encode(username + ":" + password)

var IssueURL = "https://xxxx.service-now.com/api/now/v2/table/incident";
var IssueData = {
'short_description':'Description Goes Here',
'priority':'3',
'type':'Normal',
'assignment_group':'Group Goes Here',
};

// Call the  API
var payload = JSON.stringify(IssueData);

var headers = { "Accept":"application/json",
"Content-Type":"application/json",
"Authorization": UserCredentials,
};

var options = { "method":"POST",
"headers": headers,
"payload" : payload
};

var response = UrlFetchApp.fetch(IssueURL, options);

 if (response.getResponseCode() == 401) {
 Browser.msgBox("Error retrieving data for URL" + IssueURL + ":" + response.getResponseCode() + ":" + response.getContentText());
 return "";
 }

//
// Parse the JSON response to use the Issue Key returned by the API in the email
//
var dataAll = JSON.parse(response.getContentText());
var issueKey = dataAll.number
}

How would this be written in SIL, so that it would execute in Power Script ?

1 answer

1 vote
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2018

Hello,

I think it would be like this:

 

struct property { 
string property;
string value;
}
struct properties {
property [] properties;
}
struct returnData {
string status;
string issueId;
}
property [] propertyArray;
property p;
properties newIssue;
p.property = "short_description";
p.value = "Description Goes Here";
propertyArray += p;
p.property = "priority";
p.value = "3";
propertyArray += p;
p.property = "type";
p.value = "Normal";
propertyArray += p;
p.property = "assignment_group";
p.value = "Group Goes Here";
propertyArray += p;
newIssue.properties += propertyArray;
string username = "user";
string password = "Password";
HttpRequest request;
HttpHeader header = httpCreateHeader("Accept", "application/json");
request.headers += header;
header = httpBasicAuthHeader(username, password);
request.headers += header;
header = httpCreateHeader("Content-Type", "application/json");
returnData result = httpPost("https://xxxx.service-now.com/api/now/v2/table/incident", request, newIssue);
return result.issueId;

Suggest an answer

Log in or Sign up to answer