Skip to main content
14-Alexandrite
August 10, 2021
Solved

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

  • August 10, 2021
  • 1 reply
  • 4274 views

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

 

 

Best answer by PaiChung

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.

1 reply

22-Sapphire I
August 11, 2021

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

 

RM1214-AlexandriteAuthor
14-Alexandrite
August 13, 2021

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

 

PaiChung22-Sapphire IAnswer
22-Sapphire I
August 13, 2021

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.