Skip to main content

Notifications

Small and medium business | Business Central, N...
Unanswered

Can anyone help me on this issue. I am facing this issue "Microsoft.Dynamics.Nav.Runtime.NavHttpContent variable not initialized"

Posted on by 10

Hi Community,


Can anyone help me on below issue.
When i'm trying to read the data from the D365 standard Rest API response getting the below error "Microsoft.Dynamics.Nav.Runtime.NavHttpContent variable not initialized."
Below is the code i'm using :

var
        client: HttpClient;
        Content: HttpContent;
        gHeaders: HttpHeaders;
        lHeaders: HttpHeaders;
        Request: HttpRequestMessage;
        Response: HttpResponseMessage;
        Url: Text;
        APIKey: Text;
        RString: Text;
        lText: Text;
        ResHeaders: HttpHeaders;
        ResContent: HttpContent;
Begin 
lText := 'scope=APIServices&grant_type=client_credentials';
Content.Clear();

        Content.WriteFrom(lText);
        Request.SetRequestUri(Url);
        gHeaders.Clear();
        lHeaders.Clear();

        Content.GetHeaders(lHeaders);
        lHeaders.Remove('Content-Type');
        lHeaders.Add('Content-Type', 'application/x-www-form-urlencoded');
        Content.GetHeaders(lHeaders);

        Request.GetHeaders(gHeaders);
        gHeaders.add('accept', 'application/Json');
        gHeaders.add('authorization', APIKey);
        Request.Content(Content);
        Request.GetHeaders(gHeaders);
        Request.Method := 'get';
   
        IF client.Send(Request, Response) THEN
            IF NOT Response.IsSuccessStatusCode THEN
                Error('Web service returned error:\\' + 'Status code: %1\' + 'Description: %2',
                        Response.HttpStatusCode(), Response.ReasonPhrase());

        Response.Content().ReadAs(RString);
        JsonReadWrite.ReadJSonToJSonBuffer(RString, JsonBuffer);
END;

Getting the error at this line : Response.Content().ReadAs(RString);

  • Shahzaib Nazim Profile Picture
    Shahzaib Nazim 10 on at
    RE: Can anyone help me on this issue. I am facing this issue "Microsoft.Dynamics.Nav.Runtime.NavHttpContent variable not initialized"

    Yes, I have already Allow HttpClient Request in the extension.

  • Greg Kujawa Profile Picture
    Greg Kujawa 610 on at
    RE: Can anyone help me on this issue. I am facing this issue "Microsoft.Dynamics.Nav.Runtime.NavHttpContent variable not initialized"

    Do you have Allow HttpClient Requests defined in your extension?

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,232 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans