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);
Yes, I have already Allow HttpClient Request in the extension.
Do you have Allow HttpClient Requests defined in your extension?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,232 Super User 2024 Season 2
Martin Dráb 230,064 Most Valuable Professional
nmaenpaa 101,156