4 Replies Latest reply on Aug 23, 2017 6:22 AM by pmishra-4 RSS
    pmishra-4 Explorer

    Post a row to append in infotable through REST Api

    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

      • Re: Post a row to append in infotable through REST Api
        supandey Collaborator

        Hi Prabhat, could you share the HTTP call you are making which is transferring this data to ThingWorx?

          • Re: Post a row to append in infotable through REST Api
            pmishra-4 Explorer

            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();RestCall.png