Dear All ,I'm using below code to generate Access token in business central cloud. But its not generating token. Can anyone suggest how to achieve this in business central cloud
procedure MakeRequest(): Text;
var
client: HttpClient;
request: HttpRequestMessage;
response: HttpResponseMessage;
contentHeaders: HttpHeaders;
content: HttpContent;
RspJObject: JsonObject;
AccessToken, responseText, uri : Text;
begin
// Add the payload to the content
//content.WriteFrom(payload);
//Add uri
uri := 'gsp.adaequare.com/.../authenticate
// Retrieve the contentHeaders associated with the content
content.GetHeaders(contentHeaders);
contentHeaders.Clear();
contentHeaders.Add('Content-Type', 'application/json');
contentHeaders.Add('gspappid', 'XXX');
contentHeaders.Add('gspappsecret', 'YYY');
request.Content := content;
request.SetRequestUri(uri);
request.Method := 'POST';
if client.Send(request, response) then begin
// Read the response content as json.
response.Content().ReadAs(responseText);
RspJObject.ReadFrom(ResponseText);
AccessToken := ParseAuthTokenResponse(responseText);//Parse Json Response
//AccessToken := GetJsonTextField(RspJObject, 'access_token');
exit(AccessToken);
end;
end;
You can follow the below link
hi
try this:
local procedure AcquireToken(
AuthorizationCode: Text;
UserName: Text;
Password: Text;
ClientId: Text;
ClientSecret: Text;
Scope: Text;
RedirectURL: Text;
TokenEndpointURL: Text;
JAccessToken: JsonObject): Boolean;
var
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Content: HttpContent;
ContentHeaders: HttpHeaders;
ContentText: Text;
ResponseText: Text;
IsSuccess: Boolean;
begin
ContentText := 'grant_type=client_credentials' +
'&client_id=' + UriBuilder.EscapeDataString(ClientId) +
'&client_secret=' + UriBuilder.EscapeDataString(ClientSecret) +
'&scope=' + UriBuilder.EscapeDataString(Scope);
Content.WriteFrom(ContentText);
Content.GetHeaders(ContentHeaders);
ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/x-www-form-urlencoded');
Request.Method := 'POST';
Request.SetRequestUri(TokenEndpointURL);
Request.Content(Content);
if Client.Send(Request, Response) then
if Response.IsSuccessStatusCode() then begin
if Response.Content.ReadAs(ResponseText) then
IsSuccess := JAccessToken.ReadFrom(ResponseText);
end else
if Response.Content.ReadAs(ResponseText) then
JAccessToken.ReadFrom(ResponseText);
exit(IsSuccess);
end;
check my answer if it helped you, thanks
DAniele
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,228 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156