Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I want to insert a row in infotable named 'AlertTable' .I am posting through Postman. My JSON is:-
{
"AlertTable": {
"fieldDefinitions": {
"AlertDateTime": {
"name": "AlertDateTime",
"description": "",
"baseType": "STRING",
"ordinal": 1,
"aspects": {}
},
"AlertType": {
"name": "AlertType",
"description": "",
"baseType": "STRING",
"ordinal": 2,
"aspects": {}
},
"Description": {
"name": "Description",
"description": "",
"baseType": "STRING",
"ordinal": 4,
"aspects": {}
},
"Location": {
"name": "Location",
"description": "",
"baseType": "STRING",
"ordinal": 4,
"aspects": {}
},
"Speed": {
"name": "Speed",
"description": "",
"baseType": "INTEGER",
"ordinal": 3,
"aspects": {}
},
"VehicleNo": {
"name": "VehicleNo",
"description": "",
"baseType": "STRING",
"ordinal": 3,
"aspects": {}
}
}
},
"rows": [{
"AlertDateTime": "18_08_2017",
"AlertType": "OverSpeeding",
"Description": "AlertFound",
"Location": "Mumbai",
"Speed": "212",
"VehicleNo": "Wb222111_1"
}]
}
But it's giving error as :-
Unable To Convert From org.json.JSONObject to INFOTABLE
Hi Prabhat, could you share the HTTP call you are making which is transferring this data to ThingWorx?
Hi Sushant,
Below is the code behind http rest call
HttpResponse<String> response = Unirest.put("http://localhost:8080/Thingworx/Things/AlertVehicle/Properties/AlertTable")
.header("rest_thing_api", "e3c27605-2c66-40d6-b914-4a6bf57c1f33")
.header("userid", "Administrator")
.header("password", "admin")
.header("content-type", "application/json")
.header("cache-control", "no-cache")
.header("postman-token", "7613da3e-7d91-a41a-dd04-cc06981d9371")
.body("{\r\n\t\"AlertTable\": {\r\n\t\t\"fieldDefinitions\": {\r\n\t\t\t\"AlertDateTime\": {\r\n\t\t\t\t\"name\": \"AlertDateTime\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"STRING\",\r\n\t\t\t\t\"ordinal\": 1,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t},\r\n\t\t\t\"AlertType\": {\r\n\t\t\t\t\"name\": \"AlertType\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"STRING\",\r\n\t\t\t\t\"ordinal\": 2,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t},\r\n\t\t\t\"Description\": {\r\n\t\t\t\t\"name\": \"Description\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"STRING\",\r\n\t\t\t\t\"ordinal\": 4,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t},\r\n\t\t\t\"Location\": {\r\n\t\t\t\t\"name\": \"Location\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"STRING\",\r\n\t\t\t\t\"ordinal\": 4,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t},\r\n\t\t\t\"Speed\": {\r\n\t\t\t\t\"name\": \"Speed\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"INTEGER\",\r\n\t\t\t\t\"ordinal\": 3,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t},\r\n\t\t\t\"VehicleNo\": {\r\n\t\t\t\t\"name\": \"VehicleNo\",\r\n\t\t\t\t\"description\": \"\",\r\n\t\t\t\t\"baseType\": \"STRING\",\r\n\t\t\t\t\"ordinal\": 3,\r\n\t\t\t\t\"aspects\": {}\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\t\"rows\": [{\r\n\t\t\"AlertDateTime\": \"18_08_2017\",\r\n\t\t\"AlertType\": \"OverSpeeding\",\r\n\t\t\"Description\": \"AlertFound\",\r\n\t\t\"Location\": \"Mumbai\",\r\n\t\t\"Speed\": \"212\",\r\n\t\t\"VehicleNo\": \"Wb222111_1\"\r\n\r\n\t}]\r\n}")
.asString();
I have not seen in full detail but the call appears to be correct and assuming the JSON is formatted correctly, have you verified if the datashape assigned to Infotable is correct? I'd also recommend if you can check this post REST API Overview and Examples esp. the section in REST API Examples showing multiple property updates via Postman
JSON is correctly formatted . Also , error is :-
Unable To Convert From org.json.JSONObject to INFOTABLE
This means JSON Formatt is correct.
Do i will have to explicitly parse the JSON into infotable?