Jump to content

misc_bb

Members
  • Content Count

    65
  • Joined

  • Last visited

Everything posted by misc_bb

  1. I was able to work with it on Delphi 10.4 using REST components but man MS Graph API is such a complicated api. lol Maybe because when I started on it, they were just starting to unify their API into MS Graph. Got referred to multiple documentations. So some data being pulled is from Graph API and others are the previous versions. We decided to stop development and let MS work on it (let it mature perhaps) hahaha
  2. We have a Datasnap REST project using the ISAPI DLL. We currently have 2 separate DLLs that co-exist within the project, this was quiet handy since we can develop separately and we can still connect both via the database. One dll is intended for mostly authentication but there's a need for us to utilized a Webmodule that needs to display a separate page and need to trigger some Servermethods calls. Our concern is the Javascript files which are generated by the Datasnap based on the functions you have in the TServermethods. We just realized that the TServemthods are actually listed in one of the Javascript files. I just realized it today. We wanted to generate the JS files in one of the DLLs in a separate folder (or maybe rename the JS filename). Is there a way can we configure this in the IDE? If you look at one of the JS files generated by datasnap: serverfunctions.js on the last line it contains all the methods you have created in the Servermethods just like here var JSProxyClassList = { "DSAdmin": ["GetPlatformName","ClearResources","FindPackages","FindClasses","FindMethods","CreateServerClasses","DropServerClasses","CreateServerMethods","DropServerMethods","GetServerClasses","ListClasses","DescribeClass","ListMethods","DescribeMethod","GetServerMethods","GetServerMethodParameters","GetDatabaseConnectionProperties","GetDSServerName","ConsumeClientChannel","ConsumeClientChannelTimeout","CloseClientChannel","RegisterClientCallbackServer","UnregisterClientCallback","BroadcastToChannel","BroadcastObjectToChannel","NotifyCallback","NotifyObject"], "TServerMethods1": ["EchoString","ReverseString"] }; The ebook by Marco Cantu did mention the WebFileDispatcher is the one responsible for it but I'm still digesting this one and figuring out how to go about a solution.
  3. I'm not sure if there's a better solution but for the meantime, we have to rename the serverfunctions.js in the WebFileDispatcher1BeforeDispatch and update also the JS reference in the HTML page. So far this is the only file that will be modified when a method is called from the DLL. So if you rename the serverfunctions.js which matches also the actual file in the JS folder, then it can update the file. I hope I am making sense here. 🙂 Just sharing if ever you have the same issue.
  4. @emailx45 yes, thank you. Just trying it out now.
  5. We were actually using Indy with Xero OAuth 1.0 but we just want to take advantage of the new features that the new Delphi versions is offering. So far all good with some few hiccups along the way but was able to get around with it.
  6. I guess not all APIs are created equal. I was able to figure out my problem by changing the body parameters to: TRESTRequestParameterKind.pkREQUESTBODY to TRESTRequestParameterKind.pkGETorPOST This is one of the function (Exchanging the code for tokens) we have for Quickbooks API integration. I have Xero and MYOB almost exactly the same code but this one wants to be different. Different APIs have different way of interacting with the Delphi REST component. It's probably the API design. In their API documentation they indicated that this is part of the "Body", so we also indicate that its part of the request body in our code but then it has a different result. So just in case you encounter these issues, sometimes it's trial and error. RESTRequest := TRESTRequest.create(nil); RESTRequest.Client := TRESTClient.create(RESTRequest); RESTRequest.SynchronizedEvents := False; RESTRequest.Client.UserAgent := qb_UserAGent; RESTRequest.Client.BaseURL := 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'; RESTRequest.Client.Accept := 'application/json'; RESTRequest.Client.ContentType := 'application/x-www-form-urlencoded'; RESTRequest.Client.Params.AddItem('Authorization', QuickbooksGetAuthorization, TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]); //QuickbooksGetAuthorization - calls for the Base64 encoded authorization RESTRequest.Client.Params.AddItem('Host', 'oauth.platform.intuit.com', TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]); //not sure if this was really required RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkGETorPOST); RESTRequest.Params.AddItem('code', authCode, TRESTRequestParameterKind.pkGETorPOST); //authCode - variable that stores the authentication code RESTRequest.Params.AddItem('redirect_uri', qb_RedirectURI, TRESTRequestParameterKind.pkGETorPOST); //qb_RedirectURI - variables that stores the redirectURI RESTRequest.Method := rmPOST; RESTRequest.Response := TRESTResponse.Create(RESTRequest); RESTRequest.Execute; Result := RESTRequest.Response.Content; Just sharing maybe some of you wants to implement the same 🙂
  7. 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.
  8. 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;
  9. 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
  10. 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.
  11. 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!
  12. 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.
  13. 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!
  14. 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]);
×