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, ...
Suggested Answer

Get JSON Response from Http request and save it into D365

(0) ShareShare
ReportReport
Posted on by 758

Hi Everyone,

Need urgent help.

I am sending data to Http request and saving the response into D365.

Below is my code,

public static void main(Args _args)
    {
        System.Exception ex;
        System.Net.WebHeaderCollection httpHeader;
        System.Net.WebClient webClient;
        System.Text.UTF8Encoding encoder;

        Map           map;
        mapEnumerator mapEnumerator;

        str         workorderNumberParm;
        str         jsonResponse;

        str json = "{\"EquipmentNumber\":\"11030143\",\"ExecutingDepartmentCode\":\"2010\",\"RequestedDepartmentCode\":\"2010\",\"ScheduledDate\":\"2020-04-08\",\"PlanDate\":\"2020-04-10\",\"PlanCompletionDate\":\"2020-04-15\",\"ReasonCode\":\"RS001\",\"ReasonDescription\":\"Reason Description\",\"Description\":\"Api wokorder new Parameter\",\"Priority\":\"Normal\",\"authToken\":\"CreatingfromoutsideKey123\"}";

        try
        {
            
            webClient = new System.Net.WebClient();
            httpHeader = new System.Net.WebHeaderCollection();
            httpHeader = webClient.Headers;
            httpHeader.Add("Authorization", "Bearer CreateKey123");
            httpHeader.Add("Content-Type", "application/json");
            encoder = new System.Text.UTF8Encoding();
            System.Byte[] encodedBytes = encoder.GetBytes(json);
            System.Byte[] response = webClient.UploadData("http://217.182.200.75:8018/api/Createworkorder/Create", encodedBytes);
            jsonResponse = webClient.Encoding.GetString(response);
            
            Info(strFmt("Response : %1",jsonResponse ));            

            map = RetailCommonWebAPI::getMapFromJsonString(jsonResponse);
            workorderNumberParm = map.lookup("WorkorderNumber");
            Info(strFmt("workorderNumberParm %1", workorderNumberParm));

        }
        catch(Exception::CLRError)
        {
            ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
        }

    }

In response infolog shows the desired response , the same which I got through Postman tool

which looks like

"{\"WorkorderNumber\":\"ELE/2020/00038\",\"Status\":\"Success!\",\"ErrorCode\":\"6000\"}"

However when I debug the code, the compiler shows the value of response as,

"\"{\\\"WorkorderNumber\\\":\\\"ELE/2020/00038\\\",\\\"Status\\\":\\\"Success!\\\",\\\"ErrorCode\\\":\\\"6000\\\"}\""

Due to this 

 map = RetailCommonWebAPI::getMapFromJsonString(jsonResponse);

I get null value in map variable.

Please suggest some solution.

Thank you in advance.

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rhushikesh,

    Try to use contract class and parse json to it.

    community.dynamics.com/.../how-to-deserialize-json-file-in-d365fo

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans