Jump to content

misc_bb

Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

2 Neutral

1 Follower

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. misc_bb

    New to Json

  2. I have a Webbroker via the IIS that is processing some data and plans to send the JSON data to a different page. I want to apply POST data to an HTTPS URL using Indy or REST components. Is this possible even if the URL is not REST API enabled? What I've done is applying the HTML POST Method without doing the Form Method with REST component but doesn't seem to work or this is just not applicable? Thank you.
  3. misc_bb

    RESTRequest Timeout

    This post happens to resolved my issue. I did follow his code structure though. https://quality.embarcadero.com/browse/RSP-31067
  4. misc_bb

    Using Indy with Xero API

    Thank you Remy. For the BASIC formatting my UrlEncode function includes already the BASIC keyword but I'll definitely try the Indy base64 encoder. I was expecting that Xero will more details as to why I got a Bad Request but not much. I'm suspecting it has something to do with the Basic Authentication parameters with Indy. I'll give this a try. With regards to enabling the Basic Authentication to True, does this mean that the Username and Password are automatically encoded in base64? I did read your comments on this in Stackoverflow but I was hesitant because Xero expects it to be encoded. Thank you very much!
  5. misc_bb

    Using Indy with Xero API

    This is a Webbroker & Indy implementation with Xero API in Delphi 10.4 Patch 1 I'm just wondering why I get a 200 OK in the page when this code is process, but the actual response of the Idhttp.post is a Bad Request. My code looks like this: TRY my_http := TIdHTTP.Create(nil); sCode := 'codehere234asfds3423'; //tempString is Basic + base64 encoding of clientid & clientsecret tempString := StringReplace(UrlEncode(sClientID + ':' + sClientSecret),#$D#$A, '', [rfReplaceAll]); Parameters := TStringList.Create; Parameters.Add('grant_type=authorization_code'); Parameters.Add('code=' + sCode); Parameters.Add('redirect_uri=' + 'http://localhost:30001/testXeroLogin'); try my_http.Request.CharSet := 'utf-8'; my_http.Request.UserAgent := 'DataBizApp'; my_http.Request.BasicAuthentication := false; ssl := TIdSSLIOHandlerSocketOpenSSL.Create(my_http); ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; my_http.IOHandler := ssl; my_http.Request.Accept := 'application/json'; my_http.Request.ContentType := 'application/x-www-form-urlencoded'; my_http.Request.CustomHeaders.FoldLines := false; my_http.Request.CustomHeaders.AddValue('Authorization', tempString); post_response := my_http.Post('https://identity.xero.com/connect/token', Parameters); Response.Content := '<HTML><BODY>' + post_response + '</BODY></HTML>'; EXCEPT on e: Exception do begin Logfile(ClassName + '.testProcess: ' + e.Message); Logfile('Post Response: ' + post_response); end; END; finally my_http.Free; Parameters.Free; end; I set BasicAuthentication to False since the Authorization needs to be encoded in Base64. I hope I am right with what I'm doing. Any help would be appreciated. Thank you.
  6. misc_bb

    RESTRequest Timeout

    We are currently working on migrating our project with a new authentication for the xero api. This code works find when we are using a Datasnap stand-alone application, but when we apply it in ISAPI DLL the RESTRequest.Execute line, it will just stop. I'm running out of options. I don't know if this is a bug or something but it works just find with the Stand-Alone application and localhost setup. But if we apply the DLL and using our web URL it just stop and doesn't continue at all. Any ideas would be greatly appreciated. Many thanks! function TXero2.GetAccessToken(Authorization, sAuthCode, ReDirectURI: AnsiString): AnsiString; begin TRY ResetRESTComponentsToDefaults; RESTClient.UserAgent := XeroUserAgent; RESTRequest.Client := RESTClient; RESTClient.BaseURL := XeroAPIIdentityURL; RESTClient.ContentType := 'application/x-www-form-urlencoded'; RESTClient.Params.AddItem('Authorization', Authorization, TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]); RESTRequest.Resource := 'connect/token'; RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('code', sAuthCode, TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('redirect_uri', ReDirectURI, TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Method := TRESTRequestMethod.rmPOST; RESTRequest.Execute; result := Restresponse.Content; EXCEPT on e: Exception do Codesite.Send(ClassName + '.GetAccessToken: ' + e.Message); END; end;
  7. 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.
  8. misc_bb

    Xero API with Delphi Datasnap REST

    After careful review I think REST component doesn't have any option to get the entire header and parameters. Although I was able to get my code working. So, I'll just share to you. RESTClient.BaseURL := 'https://identity.xero.com/'; RESTClient.ContentType := 'application/x-www-form-urlencoded'; RESTClient.Params.AddItem('Authorization', Authorization, TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]); RESTRequest.Resource := 'connect/token'; RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('code', sAuthCode, TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('redirect_uri', ReDirectURI, TRESTRequestParameterKind.pkREQUESTBODY); Logfile('authorization:' + Authorization + '&grant_type:authorization_code' + '&code:' + sAuthCode + '&redirect_uri:' + ReDirectURI); RESTRequest.Method := TRESTRequestMethod.rmPOST; RESTRequest.Execute; I'm not exactly sure what happen in my previous code but I did transfer the header parameter in the RESTClient instead of placing it in RESTRequest and added the Restrequestparameteroption. Take note also that the Authorization here has a base64 encoding as specified by Xero but during the Delphi encoding it added a linefeed which was also one of the reasons why I keep getting a bad request but I had to remove manually before passing it here. tempFile := 'Basic ' + X.UrlEncode(sClientID + ':' + sClientSecret); sAuthorization := StringReplace(tempFile, #$D#$A, '', [rfReplaceAll]);
  9. We are building a Xero API with OAuth2 using the REST components in Delphi Datasnap. We have been following this Xero API flow: https://developer.xero.com/documentation/oauth2/auth-flow but we are encountering issues on Step 3. It gives me all the time an error of 'invalid_client' but when I tested the values in Postman, I was able to retrieved what is expected successfully with no errors. Here is part of the code. RESTClient.BaseURL := 'https://identity.xero.com/'; RESTClient.ContentType := 'application/x-www-form-urlencoded'; RESTRequest.Resource := 'connect/token'; RESTRequest.Params.AddItem('Authorization', Authorization, TRESTRequestParameterkind.pkHTTPHEADER); RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('code', sAuthCode, TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Params.AddItem('redirect_uri', ReDirectURI, TRESTRequestParameterKind.pkREQUESTBODY); RESTRequest.Method := TRESTRequestMethod.rmPOST; RESTRequest.Execute; I am suspecting it was the base64encoding part, but I was able to correct that one and I was able to successfully test the values in Postman. Is there a way, I can retrieve the full URI or REST parameters that is being sent by this component? I want to see is the entire value that is being sent by the RESTRequest. Is this possible? Thank you!
×