web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

(0) ShareShare
ReportReport
Posted on by 24

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.

Thanks

*This post is locked for comments

I have the same question (0)
  • siddharth.kumar Profile Picture
    24 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    Thanks a lot, Kokulan your solution worked out.

  • Verified answer
    Kokulan Profile Picture
    18,054 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    Hi siddharth

    You are getting the error for the following reason in my view

    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.

    Let me know how it goes

    Hope this helps

  • siddharth.kumar Profile Picture
    24 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    Hi Kokulan, The query variable has the action name :

    var query = "new_FedExTracking";

    The ajax post is successfully working with simple JSON obj, but with complex json, it's throwing 400.

  • Kokulan Profile Picture
    18,054 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    Could you share whats in the query variable?

  • siddharth.kumar Profile Picture
    24 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    Hi David, The question has been asked in the correct forum. I am using Dynamics 365 CRM Online.

  • David Jennaway Profile Picture
    14,065 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    It looks like you're using Dynamics 365 Finance & Operations, so it would be best to post this in the Dynamics 365 Finance & Operations Forum

  • siddharth.kumar Profile Picture
    24 on at
    RE: An unexpected StartObject node was found for the property named ShipmentDetails when reading from the JSON reader

    The JSON payload on which I am getting error is :

    
    {"IsCreateShipmentTask":true,"ShipmentDetails":{"ShipperName":"Microsoft","ShipperCompany":"TEST","ShipperPhone":"5435345345","ShipperStreet":["3454","Gees Miller Road"],"ShipperCity":"Conyers","ShipperStateCode":"GA","ShipperPCode":"30013","ShipperCountryCode":"US","RecipientName":"Fasg","RecipientCompany":"TEST1","RecipientPhone":"46456645654","RecipientStreet":["4545","Gees Miller Road"],"RecipientCity":"Conyers","RecipientStateCode":"GA","RecipientPCode":"30013","RecipientCountryCode":"US","RecipientIsResidential":true,"Currency":"USD","ShipmentServiceType":"Fedex 2day","IsCOD":true,"LineItems":[{"Height":"13","Length":"20","Width":"25","Weight":0.5,"WeightUnitInLB":true,"CODAmount":198,"DimensionUnitInCM":false,"CommodityPieces":2,"CommodityDescription":"Shares","CommodityUnitPrice":99,"CommodityCountryOFManufacture":"US","CommodityCustomsValue":0}]}}
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans