cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

How to call RestApi

Harsha11
6-Contributor

How to call RestApi

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;

 

 

1 REPLY 1
slangley
23-Emerald II
(To:Harsha11)

Hi @Harsha11.

 

Apologies for the delay in responding to your post.

 

Have you defined the basetype for the output?  If you have already resolved this issue, please post your solution here for the benefit of others with similar issues.

 

Regards.

 

--Sharon

Top Tags