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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to get all alerts in JSON format using REST API from InfoTable

Swapnil_More
14-Alexandrite

How to get all alerts in JSON format using REST API from InfoTable

Hello,

I created custom service to fetch InfoTable data through Rest API and tried converting the output of the INFOTABLE using INFOTABLE.toJSON() function and set the output parameter accordingly but while I am trying to access it using rest API I am not getting the output in the JSON format.829D10B7.PNG

var params = {
	maxItems: undefined /* NUMBER */,
	onlyUnacknowledged: undefined /* BOOLEAN */,
	onlyAcknowledged: undefined /* BOOLEAN */
};

// result: INFOTABLE dataShape: "AlertSummary"
var data = me.GetAlertSummary(params);

var params = {
	table: data /* INFOTABLE */
};

// result: JSON
var result = Resources["InfoTableFunctions"].ToJSON(params); 
Regards,
Swapnil More
6 REPLIES 6
PaiChung
22-Sapphire I
(To:Swapnil_More)

I believe for this to work you would need the datashape definition to also be part of that infotable.

I forget what other methods are available, I think you might be able to use Stringify

Swapnil_More
14-Alexandrite
(To:PaiChung)

Hello @PaiChug, I tried attaching the data shape and then using stringfy() method on it however the result which I am getting is of the form whose image is attached below where it says BaseType = String and could not get the data which is stored in the infotable.I tried executing the service using REST API from Browser as well as Postman.

Regards,
Swapnil More
PaiChung
22-Sapphire I
(To:Swapnil_More)

With the DataShape defined, the ToJSON should work I believe, but I guess that wasn't the case either?

PaiChung
22-Sapphire I
(To:Swapnil_More)

Your output type of the Service is JSON right?

You may also need to set the "Accept" header to let the server know what kind of response your HTTP request needs. You can set the Accept and Content-Type headers (the format of any data you are sending) in Postman

 

The different Accept headers that ThingWorx can handle are shown in the guide linked below. Not all of the Accept types are available for every REST call:

https://developer.thingworx.com/en/resources/guides/thingworx-rest-api-quickstart/introduction-thingworx-rest-api-design

 

Because you are sending back a more complicated data structure, the Accept header may just set the "wrapper" around the data you are trying to read and not the actual data itself.

Hello,

In Thingworx,when I executed service I get result in table format ("JSON / String / Infotable") with header as per datashape but when I called same service through RestAPI method or Postman then result will be in single word "JSON / String / Infotable" as per service output.I want result in form of table like Thingworx. I attached Postman service for your reference.

The problem which I am facing is I am unable to view the contents of the INFOTABLE even after I set the accept and content type parameters along in the postman. 

tempsnip.png

 

 

Regards,
Swapnil More
Top Tags