How to call RestApi
- July 12, 2018
- 1 reply
- 1074 views
Hi,
I am using below code for creating service to call RestAPI in thingworx ,
while executing service it is not giving any error but at the same time it is not giving output also,
please suggest what am i missing
below is the code:
var params = {
url: "http://localhost:8080/greeting/"
};
// result: JSON
var json = Resources["ContentLoaderFunctions"].GetText(params);
var obj = JSON.parse(json);
//var obj = JSON.parse('[{"id":69,"content":"Hello, World!"}, {"id":70,"content":"Hello, Bhau!"}]');
var paramsDS = {
infoTableName : "InfoTable",
dataShapeName : "RES_DS"
};
var infoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(paramsDS);
//for (var elem in json)
for (var i=0; i<obj.length; i++)
{
var row = obj[i];
//var userIdVal = row.id;
var idVal = row.name;
// var contentVal = row.content;
// var titleVal = row.title;
// var bodyVal = row.body;
infoTable.AddRow({id:idVal});
// infoTable.AddRow({ id:idVal, content:contentVal});
}
var result = infoTable;

