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);