<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic postJSON error with thingworx in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974348#M67876</link>
    <description>&lt;P&gt;Hi Team&lt;BR /&gt;&lt;BR /&gt;I have an issue a with a PostJSON request.&lt;BR /&gt;I have tested succesfully the content below with PostMan.&lt;BR /&gt;&lt;BR /&gt;When invoking this a POSTJSON request, seems it can not handle orrectrly the content data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        var c=[
        {
        'login':'temp',
        'SensorData':[
         {
        "Timestamp": 1727265323000,
        "Quantity": "Temperature",
        "Value": "19.2",
        "Unit": "°C",
        "DataType": "Decimal",
        "ValueOK": true
        }
         ]
        }
          ]  ;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let params = {
	proxyScheme: "https",
	headers: {
        "Client": "xxx", 
        "Branch": "xxx",
        "Api-Key": "xxx",
        "version": "3.0"
	},
	url: "https://api.platform.twinzo.eu/v3/sensors/batch",
	content: c,
};

// result: JSON
let result = Resources["ContentLoaderFunctions"].PostJSON(params);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Any idea of why it fails ?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; "Message": "sensorContract.array:\n\tCannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.IEnumerable`1[Core.Contract.V3.Sensors.SensorBatchContract]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List&amp;lt;T&amp;gt;) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'array', line 1, position 9.\n",
    "responseStatus": {
        "reasonPhrase": "Bad Request",&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2024 14:35:39 GMT</pubDate>
    <dc:creator>LaurentGermain</dc:creator>
    <dc:date>2024-09-27T14:35:39Z</dc:date>
    <item>
      <title>postJSON error with thingworx</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974348#M67876</link>
      <description>&lt;P&gt;Hi Team&lt;BR /&gt;&lt;BR /&gt;I have an issue a with a PostJSON request.&lt;BR /&gt;I have tested succesfully the content below with PostMan.&lt;BR /&gt;&lt;BR /&gt;When invoking this a POSTJSON request, seems it can not handle orrectrly the content data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        var c=[
        {
        'login':'temp',
        'SensorData':[
         {
        "Timestamp": 1727265323000,
        "Quantity": "Temperature",
        "Value": "19.2",
        "Unit": "°C",
        "DataType": "Decimal",
        "ValueOK": true
        }
         ]
        }
          ]  ;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let params = {
	proxyScheme: "https",
	headers: {
        "Client": "xxx", 
        "Branch": "xxx",
        "Api-Key": "xxx",
        "version": "3.0"
	},
	url: "https://api.platform.twinzo.eu/v3/sensors/batch",
	content: c,
};

// result: JSON
let result = Resources["ContentLoaderFunctions"].PostJSON(params);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Any idea of why it fails ?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; "Message": "sensorContract.array:\n\tCannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.IEnumerable`1[Core.Contract.V3.Sensors.SensorBatchContract]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List&amp;lt;T&amp;gt;) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'array', line 1, position 9.\n",
    "responseStatus": {
        "reasonPhrase": "Bad Request",&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 14:35:39 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974348#M67876</guid>
      <dc:creator>LaurentGermain</dc:creator>
      <dc:date>2024-09-27T14:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: postJSON error with thingworx</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974466#M67878</link>
      <description>&lt;P&gt;could you try like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;content: JSON.stringify(c)&lt;/LI-CODE&gt;&lt;P&gt;TWX always has some special behavior with json-arrays, resulting in a wrapped array in a json object {array:[&amp;lt;originalarray&amp;gt;]}&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2024 16:42:10 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974466#M67878</guid>
      <dc:creator>nmutter</dc:creator>
      <dc:date>2024-09-28T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: postJSON error with thingworx</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974467#M67879</link>
      <description>&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;Thx, unfortunately, it produces the same error. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 28 Sep 2024 16:51:59 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974467#M67879</guid>
      <dc:creator>LaurentGermain</dc:creator>
      <dc:date>2024-09-28T16:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: postJSON error with thingworx</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974470#M67880</link>
      <description>&lt;P&gt;Found a solution ( similar to&amp;nbsp;&amp;nbsp;&lt;A href="https://community.ptc.com/t5/ThingWorx-Developers/API-call-PUT-JSON-content-array-instead-of-object/m-p/653352#M43453" target="_blank"&gt;https://community.ptc.com/t5/ThingWorx-Developers/API-call-PUT-JSON-content-array-instead-of-object/m-p/653352#M43453&lt;/A&gt;)&amp;nbsp;:&lt;/P&gt;&lt;P&gt;Using &lt;STRONG&gt;PostText&lt;/STRONG&gt; instead of &lt;STRONG&gt;PostJSON&lt;/STRONG&gt;, and adding in the header:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;contentType: "application/json"&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2024 17:17:44 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/postJSON-error-with-thingworx/m-p/974470#M67880</guid>
      <dc:creator>LaurentGermain</dc:creator>
      <dc:date>2024-09-28T17:17:44Z</dc:date>
    </item>
  </channel>
</rss>

