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 :
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"

(0) ShareShare
ReportReport
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);

I have the same question (0)
  • Greg Kujawa Profile Picture
    565 on at

    Do you have Allow HttpClient Requests defined in your extension?

  • Shahzaib Nazim Profile Picture
    10 on at

    Yes, I have already Allow HttpClient Request in the 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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans