Filtering the get rest api and returning only the filtered data
- March 12, 2020
- 4 replies
- 2593 views
Hi,
I am using get rest api call and fetching a set of Id and Name. I wanted to pass an argument or filter using the Id field and fetch the data for that respective id alone. How can I acheive this in thingworx javascript? I have mentioned my get service below.
var headers = { "Content-Type": "application/json"};
var url = "http://"+ me.host + ":" + me.port + "/api/parametersets";
var params = {
proxyScheme: undefined /* STRING */,
headers: headers /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: url /* STRING */,
timeout: 15 /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};
try {
var json = Resources["ContentLoaderFunctions"].GetJSON(params);
var param1s = {
infoTableName : "InfoTable",
dataShapeName : "FTMParameterSetDS"
};
var newInfo = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(param1s);
var value = json.array.length;
for(var i=0; i<json.array.length; i++)
{
if (json.array[i].Id != null && json.array[i].Id !== "" && json.array[i].Id !=" ")
{
if (json.array[i].Name != null )
{
newInfo.AddRow({Id:json.array[i].Id,
Name:json.array[i].Name});
}
}
}
result = newInfo;
}
catch(err)
{
me.CloseSession();
}
I have attached my output for this get api in which I want to filter w.r.t Id column.
Thanks in advance,
svisveswaraiya.

