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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

OData JSON - Header and line format

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

Hope you are doing good.

I am working on OData and needs your help.

I have to create OData(JSON) for sales confirmation into header and line format (Below is the format)

Can you please help, how I'll create below JSON format.

{
"order_number":"Test01",
"email":"Test@gmail.com",
"total_price":"16.00",
"currency":"INR",
"line_items":
[
{
"id":"I001",
"name":"Item01",
"quantity":1,
"price":"10",
},
{
"id":"I002",
"name":"Item02",
"quantity":1,
"price":"20",
}
],
"shipping_address":
{
"first_name":"Test",
"address1":"A-2 S345",
"phone":"60606",
"city":"Delhi",
"zip":"221",
"country":"IN",
},

}

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at

    Hi Priya,

    Do you mean that you want to get data in JSON format with odata?

    You can try the url like that:

    [Your organization's root URL]/data/Customers?$format=json.

    It will list all the customers in a JSON format.

  • Community Member Profile Picture
    on at

    Thanks for your reply.

    I want to create data into header and line format (below is the structure) using OData.

    Please suggest how we can create data entity (Odata) into below structure.

    "order_number":"Test01",                                    <-----Header

    "email":"Test@gmail.com",

    "total_price":"16.00",

    "currency":"INR",

    "line_items":

                           "id":"I001",                                    <------Multiple line against a single sales confirmation

                            "name":"Item01",

                            "quantity":1,

                            "price":"10",

                           

                            "id":"I002",

                            "name":"Item02",

                            "quantity":10,

                            "price":"20",

                           

                            "id":"I003",

                            "name":"Item03",

                            "quantity":15

                            "price":"30",

  • Suggested answer
    Focus Profile Picture
    5 on at

    The below pattern will do the work.

    {

       "order_number":"Test01",

       "email":Test@gmail.com,

       "Lines": [

           {

               "LineID": "I001",

               "LineDescription": "10",

           },

           {

               "LineID": "I002",

               "LineDescription": "20",

           }

       ]

    }

  • Community Member Profile Picture
    on at

    Thanks Focus.

    Can you please give me some idea how we can achieve This OData structure.

    Thanks in advance.

  • WillWU Profile Picture
    22,361 on at

    Hi partner,

    It seem that you have a problem with JSON serialization.

    Please try to use “FormJsonSerializer“ class.

    You can create the X++ data contract classes and see the following method.

    str jsonSerializedContract = FormJSONSerializer ::serializeClass(oDataContractClass);

    Have a look at this blog:

    www.bootes.co/.../Dynamics-365-for-Finance-and-Operations-Serializing-to-JSON-from-X

  • Community Member Profile Picture
    on at

    Thanks Will WU.

    So As of now I have created Data entity to send OData.

    Please correct me if I am wrong - I understood from your last reply; I will needs to change my development strategy.

    Instead of using Data entity I'll need to create new class to show data into required structure.

    Or please let me suggest if any ways to get data into required format using Data entity.

    Thanks in advance.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Priya_D365,

    If you want to get header and lines from D365 via OData in one call, you need to use an expand the option to get it. I don't know the names of your entities, but in general, it should call URL like below:

    https:/[Your organization's root URL]/data/header_entity?cross-company=true&$filter=order_number eq 'Test018'&$expand=line_entity

    Also, you need to be sure that header_entity has a relation to line_entity otherwise expand option will not work.

  • Community Member Profile Picture
    on at

    Thanks Sergei, It's works for me.

  • Community Member Profile Picture
    on at

    Hi,

    As per Sergei advice I am able to expand standard entity (Tried standard sales confirmation header & line entity) and its working fine.

    But when I have created two custom data entity (that is confirmation header and line entity);and when accessing single OData; its working fine but when I expand two entities (Custom); its throwing below error message:

    OData URL:

    https:/Base URL/data/SalesOrderConfirmHeader?cross-company=true&$filter=ConfirmationNumber eq 'A0001' &$expand=SalesOrderConfirmLine

    <Error>

    <Message>An error has occurred.</Message>

    <ExceptionMessage>

    Could not find a property named 'SalesOrderConfirmLine' on type 'Microsoft.Dynamics.DataEntities.SalesOrderConfirmHeaders'.

    </ExceptionMessage>

    <ExceptionType>Microsoft.OData.Core.ODataException</ExceptionType>

    <StackTrace>

    I am assuming it may be some issue with data entity relation.

    Could you please hep me to solve this issue:

    Header Data entity

    pastedimage1585465405874v1.png

    Line data entity:

    3582.Untitled.png

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Priya_D365,

    Try to use Role name from the relation in expand section SalesOrderConfirmationLines.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans