Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

Posted on by 20

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

  • siddharth.kumar Profile Picture
    siddharth.kumar 20 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
    Kokulan 18,048 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
    siddharth.kumar 20 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
    Kokulan 18,048 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
    siddharth.kumar 20 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
    David Jennaway 14,063 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
    siddharth.kumar 20 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans