Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello Experts,
I retrieves information in json format using rest api service and i need to show the result in the mashup!, any idea...
I created a property of type info table called OPJ that has a datashap with few attributes that i need to retrieve from the output(json) and i use the following code:
let params = {
headers:{ "Content-Type":"application/json","Accept":"*/*","Accept-Encoding":"gzip, deflate, br","X-HP-HMAC-Authentication": "***********","X-HP-HMAC-Date": "*********","X-HP-HMAC-Algorithm": "SHA1"} /* JSON */,
url: "********************************" /* STRING */,
content: {"aaa-org-ids" : ["ed8eb542-5a5e-46b0-80bd-a1768cc43da8"],"start" : "2021-05-03","end" : "2021-05-09", "active" : "false"} /* JSON */,
};
// result: JSON
let dj = Resources["ContentLoaderFunctions"].PostJSON(params);
logger.warn(dj.length);
for(let i=0;i<dj.length;i++){
me.OPJ.AddRow({printed_date:dj.data[i].printed_date,build_unit_serial_number:dj.data[i].build_unit_serial_number, processing_station_serial_number:dj.data[i].processing_station_serial_number,
processing_station_part_number:dj.data[i].processing_station_part_number,printer_model_name:dj.data[i].printer_model_name});
}
let result = me.OPJ;
However i have the following error:
Regards,
Yous
There is no direct way to display JSON on a mashup, you can however convert the output of the service to basetype string and then display it but the structure wont be pretty.
Alternatively, you can convert the JSON to an infotable and then display it on a mashup. You can refer below articles for steps of converting JSON to infotable,
There are some other community post as well which you can refer for the same.
Regards,
Sachin
Hello @SachinSharma ,
Thanks for information, in my case none of the two articles was helpful but wth the following steps:
-First create a datashape (JsonOutPutDS) with all attributes need to retrieve from the json and create a property of type infotable (itjson) in the thing where you will run the service below and link it to the created datashape
-Create a service with following code (i put * to hide my informations):
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(JsonOutPutDS)
let resultTemp = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "JsonOutPutDS"
});
let params = {
headers:******************************,
url: **********************************,
content: ***************************** /* JSON */,
};
// result: JSON
let jsont = Resources["ContentLoaderFunctions"].PostJSON(params);
logger.warn(JSON.stringify(jsont));
for(var i=0; i<jsont.data.length;i++){
let item=jsont.data[i];
resultTemp.AddRow({job_id:item.job_id,************************});
}
me.itjson=resultTemp;
var result = me.itjson;
-In the output of the service, set it to infotable and assin it to the datashape created in first step
hope it helped
Regards,
Youssef