Jump to content
Sign in to follow this  
misc_bb

Client API with Webroot

Recommended Posts

I'm building a simple client app to retrieve data from a Webroot API. I tested authentication in Postman and everything works just fine. I'm trying to replicate what I have in Postman in Delphi using the REST client components but I encounter an error which I don't really know what exactly is causing it but maybe you guys can help me out. 

 

RESTClient1.BaseURL := 'https://unityapi.webrootcloudav.com/';

  RESTClient1.Accept := 'application/json';
  RESTClient1.Params.AddItem('Content-Type','application/x-www-form-urlencoded',TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
  RESTClient1.Params.AddItem('Authorization', 'Basic ' + sAuthorization, TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
  RESTRequest1.Resource := 'auth/token';

  RESTRequest1.Params.AddItem('username', sUsername, TRESTRequestParameterKind.pkREQUESTBODY);
  RESTRequest1.Params.AddItem('password', sPassword, TRESTRequestParameterKind.pkREQUESTBODY);
  RESTRequest1.Params.AddItem('grant_type', 'password', TRESTRequestParameterKind.pkREQUESTBODY);
  RESTRequest1.Params.AddItem('scope', '*', TRESTRequestParameterKind.pkREQUESTBODY);

  RESTRequest1.Method := TRESTRequestMethod.rmPOST;
  RESTRequest1.Execute;
  memo1.Lines.Add(RESTResponse1.Content);

 

For the sAuthorization variable - it's already a base64 encoded value as specified in the Webroot guidelines: https://unityapi.webrootcloudav.com/Docs/en/APIDoc/PasswordAuthentication

Also sUsername, sPassword they already have corresponding values. 

This request is for authentication which will return an access token. But it seems the grant_type value is causing the error which i cannot figure out.

 

When I run my code, it always return this error: 

{"statusCode":400,"requestId":"54bf21a8-cee9-4bef-ac5d-2704dd9f23c1","error":"unsupported_grant_type","error_description":"Invalid grant type has been sent.","AdditionalInformation":{}}

 

Maybe you have the same experienced and was able to resolved, please let me know. Thank you.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×