Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Consume json from exte...
Finance forum
Suggested answer

Consume json from external system

editSubscribe (1) ShareShare
ReportReport
Posted on by 327
Hi ,
 
I need to consume json from external system but the json is not in the format we generally have when trying to import it through custom service.
I have pasted the sample json below, can you suggest if we can import the same using custom service or we need a middleware to format this for F&O format json.
 
{    /schemaVersion/: /5.0.0/,    /id/: /ID-TEST01-TR-el/,    /lastModified/: /2024-04-04T12:00:09.000+00:00/,    /traceId/: /25rt2fdc-662-41f0-94ec-e21rr485/,    /eventType/: /xyz/,    /eventTime/: /2024-04-29T12:38:28.9637814+00:00/,    /filter/: {        /contentabc/: [            /xyz/        ]    },    /delta/: true,    /data/: {        /itemNo/: /TEST01/,        /itemType/: /TYPE1/,        /countryCode/: /GR/,        /languageCode/: /el/,        /latestUpdate/: /2024-04-04T12:00:09.000+00:00/,        /productType1/: {            /productTypeNo/: /10045/,            /productTypeName/: /ABC/,            /updateDate/: /2020-06-02T11:16:25.000+00:00/        },        /productName1/: [            {                /productNameNo/: /1003/,                /sortNo/: 1,                /updateDate/: /2017-12-12T18:32:28.000+00:00/            }        ],        /businessStructureLocal/: [            {                /validFrom/: /1998-09-01T00:00:00.000+00:00/,                /validTo/: /2000-08-31T23:59:59.000+00:00/,                /Name/: /TEST01/            }        ]    }}
Thanks!!
  • Dev Profile Picture
    Dev 327 on at
    Consume json from external system
    Thanks Martin.
     
    If we get a json with too much data and we need just few of them is it ok to consume it as it is by just creating contract class with the data we require or should we transform the json using middleware to send obly the required fields if we use custom services.
  • Martin Dráb Profile Picture
    Martin Dráb 223,308 Super User on at
    Consume json from external system
    No, you can't use DMF to import JSON and you can't use any arbitrary format there - you must respect the format from the data entity. Therefore you'd need a transformation.
  • Dev Profile Picture
    Dev 327 on at
    Consume json from external system
    So the data sent by json has more than 100 fields but we need just around 20 of them so is it a good idea to use a middleware to transform the json to only send the data that we need.
     
    Also , can we use DMF for processing this json in anyway as I don't see the json format in the supported formats.
     
    Thanks!
  • Martin Dráb Profile Picture
    Martin Dráb 223,308 Super User on at
    Consume json from external system
    Let me repost the code to make it easier to read.
    {
        "schemaVersion": "5.0.0",
        "id": "ID-TEST01-TR-el",
        "lastModified": "2024-04-04T12:00:09.000+00:00",
        "traceId": "25rt2fdc-662-41f0-94ec-e21rr485",
        "eventType": "xyz",
        "eventTime": "2024-04-29T12:38:28.9637814+00:00",
        "filter": {
            "contentabc": ["xyz"]
        },
        "delta": true,
        "data": {
            "itemNo": "TEST01",
            "itemType": "TYPE1",
            "countryCode": "GR",
            "languageCode": "el",
            "latestUpdate": "2024-04-04T12:00:09.000+00:00",
            "productType1": {
                "productTypeNo": "10045",
                "productTypeName": "ABC",
                "updateDate": "2020-06-02T11:16:25.000+00:00"
            },
            "productName1": [
                {
                    "productNameNo": "1003",
                    "sortNo": 1,
                    "updateDate": "2017-12-12T18:32:28.000+00:00"
                }
            ],
            "businessStructureLocal": [
                {
                    "validFrom": "1998-09-01T00:00:00.000+00:00",
                    "validTo": "2000-08-31T23:59:59.000+00:00",
                    "Name": "TEST01"
                }
            ]
        }
    }
    At the first glance, I don't see anything that you couldn't build a custom service for, although a transformation could make processing in F&O easier.
     
    Top-level elements such as schemaVersion or data would be parameters of the custom service methods. Then you would need contract classes for JSON objects (such as the value of data).
  • Suggested answer
    Anthony Blake Profile Picture
    Anthony Blake 862 on at
    Consume json from external system
    Hi Dev,
     
    If the service isn't done yet sure you can process json so long as it is in a valid format. Its probably an issue with your paste, but it currently contains a bunch of errors if run through a validator for example here https://jsonformatter.curiousconcept.com/
     
    You really need a json schema to go with your sample from the provider which you can developer against, but if thats not possible you can generate one using sites like this one: https://transform.tools/json-to-json-schema
     
    Alternatively, you could add some pre-processing with a Logic App and/or Azure Function, to transform your data and load through OData, Rest API, or Recurring integrations.
     
  • Layan Jwei Profile Picture
    Layan Jwei 3,079 Super User on at
    Consume json from external system
    Hi,


    you said this format doesn't match the format you generally have. What is the format you are expecting?
    and what do you mean by it doesn't match F&O json requirements? you can build your custom service in any way to accept the json you are getting.

    Or are you referring to this one?

        "contentabc":
        [
          "xyz"
        ]

    shouldn't it be like this?
        "contentabc":
        [
          "Field1" :"xyz"
        ]
  • Dev Profile Picture
    Dev 327 on at
    Consume json from external system
    Hi Anthony,
     
    We still haven't developed the custom service and only received the sample json file but not sure if we can use this as is for our custom services development or we need to transform this to adapt to F&O json requirements.
  • Suggested answer
    Anthony Blake Profile Picture
    Anthony Blake 862 on at
    Consume json from external system
    If looks like you have 3 options:
     
    1. Modify your current custom service to process the new format, or;
    2. Create a custom service to process the new format, or;
    3. Pre-process the data into the format required by your current customer service - potentially in something like a logic app
     
     

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,375 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans