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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How to create get API in Thingworx with getting all data json format ?

RM12
13-Aquamarine

How to create get API in Thingworx with getting all data json format ?

Hello,

           I want to create get API in Thingworx from service with converting data table format into json format? for this I create one query for getting all data and use tojson() snippets ..... set output as json base type, but I'm getting output in info table. I also used getjson() snippets and getting blank headers output please refer below attachments and suggest :  

 How to create get API in Thingworx with getting all data in Json format ?

 

Thanks in Advance 

 

tojson()snippets output:

RM12_0-1628603948882.png

getjson()snippets output:

RM12_1-1628604183836.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:RM12)

If you take your content as an infotable and assign it to a property

then when you do a get with 'accept-type' as application/json you should get that infotable as a json.

View solution in original post

6 REPLIES 6
PaiChung
22-Sapphire I
(To:RM12)

A GET would only work if you are reading some in memory information.

So if you set the value on a Property you should be able to retrieve that with a GET

 

RM12
13-Aquamarine
(To:PaiChung)

Thanks for giving response, Yes I want to retrieve data from PostgreSQL Database and want to convert table format data into JSON format .for this ,I tried below query in PostgreSQL when when I set output as JSON base type it gave me no result but when I set output as Infotable base type gave me table format JSON data and I want in proper JSON format Data so please refer below attachment and suggest :

How do I covert table format data into proper JSON format data ??

 

select row_to_json("tbl_machine") as json from "tbl_machine"

 

Output Getting :

RM12_0-1628849514229.png

Postman Output :

RM12_1-1628849633678.png

 

Expected Output :

sampleJSON.png

 

PaiChung
22-Sapphire I
(To:RM12)

If you take your content as an infotable and assign it to a property

then when you do a get with 'accept-type' as application/json you should get that infotable as a json.

RM12
13-Aquamarine
(To:PaiChung)

Thanks for your reply ,It works.

RM12
13-Aquamarine
(To:RM12)

Hi,I have one more que. I have Number of tables so shall I  create number of infotable property ?? 

Is there any way to get continuous data when I trigger any API ?? 

slangley
23-Emerald II
(To:RM12)

Hi @RM12.

 

For your first question, we're not clear on what you're asking. 

 

For continuous data, since we're assuming you're calling it from outside the platform, you may be able to set something up to run on a scheduled basis.

 

Please provide more information and we'll try to be more specific.

 

Regards.

 

--Sharon

Top Tags