An unexpected Start Object node was found for the property named Shipment Details when reading from the JSON reader

1,171 views
Skip to first unread message

vijay kumar

unread,
May 8, 2019, 5:26:24 AM5/8/19
to Curso de Microsoft Dynamics CRM
Hi All,

I am trying to post JSON data to the plugin via ajax. I am getting an error with 400 error code and the exception message as :

An error occurred while validating input parameters: Microsoft.OData.ODataException: An unexpected 'StartObject' node was found for property named 'ShipmentDetails' when reading from the JSON reader. A 'PrimitiveValue' node was expected.

The code is

var data =
{
"IsCreateShipmentTask": true
};

data.ShipmentDetails = PrepareShipmentData();

var jsonData = JSON.stringify(data);

$.ajax({
url: organizationUrl + "/api/data/v9.1/" + query,
type: 'POST',
contentType: "application/json; charset=utf-8",
async: false,
datatype: "json",
data: jsonData,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (responseText) {
}
});

If I modify the above JSON payload & make it as

data =
{
"IsCreateShipmentTask": true,
"ShipmentDetails" : "some value"
};

then it's working. But not with JSON objects.

Please help me out of this issue.

Vikranth Sinha

unread,
May 17, 2019, 6:33:58 AM5/17/19
to Curso de Microsoft Dynamics CRM
Hi,

When you post the JSON payload CRM is trying to convert the string in ShipmentDetails property to JSON object. It expects a simple type (string) but it found a complex type.

You could try the following and see if that helps to force CRM to not to convert the ShipmentDetails into an object

var ShipmentDataPrepped = PrepareShipmentData();

var ShipmentDataPreppedStringified = JSON.stringify(ShipmentDataPrepped );

You could try to find and replace all the double quotes with a single quote or some other character that won't be used in your shipment data.  You could all try and replace the (colon) : with some other char and see if that allows to pass it through as a string. The outcome of this should be something like the following

data =

{

"IsCreateShipmentTask": true,

"ShipmentDetails" : "-'hello'_'world'-"

};

Once you passed the JSON object into your Action code, then you can do find and replace to get your original JSON back. If you still need help regarding Microsoft Dynamics CRM Development feel free to contact me.
Reply all
Reply to author
Forward
0 new messages