I want to get access token:
I already did all steps to get client_id, client_secret and ressource and with grant_type as client_credentials and sent them all to get access token.
I test that on postman and work as expected and return that access token which I want to use dealing with sharepoint.
I want to simulate that request with AL code
But won't work and show me that body must contain the following parameter: 'grant_type'
even though I only just send that grant_type
code:
procedure GetToken()
var
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Client: HttpClient;
Content: HttpContent;
Headers: HttpHeaders;
contentJSON: Text;
myJson: Text;
link: Text;
MyJobject: JsonObject;
PayloadOutStream: OutStream;
PayloadInStream: InStream;
begin
link := 'https://accounts.accesscontrol.windows.net/c________________________b/tokens/OAuth/2';
Headers.Clear();
Request.GetHeaders(Headers);
// Headers.Add('Content-Type', 'multipart/form-data');
Request.SetRequestUri(link);
Request.Method := 'POST';
contentJSON := '{"grant_type":"client_credentials"}';
Message(contentJSON);
Content.WriteFrom(contentJSON);
Request.Content := Content;
Client.Send(Request, Response);
if Response.IsSuccessStatusCode() then
Message('Yes');
Response.Content().ReadAs(myJson);
Message(myJson);
end;
Any help is much appreciated!