![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Xojo Plugin) Egyptian eReceipt OAuth2 Client CredentialsSee more Egypt eReceipt ExamplesGet an OAuth2 access token for the Egyptian eReceipt REST API using client credentials (no interactivity with a web browser required).For more information, see https://sdk.invoicing.eta.gov.eg/ereceiptapi/01-authenticate-pos/
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Dim http As New Chilkat.Http Dim success As Boolean // Note: Any provider of a REST API, such as the Egyptian government in this case, can make life // much easier for developers by providing one or more of the following in the API documentation: // // 1) A sample CURL statement for each API call. // 2) A Postman collection, or Swagger/OpenAPI specification file. // 3) A sample of a raw HTTP request and response for each API call. // // The sample CURL statements or raw HTTP request/responses do not need to comprehensively show all // possible options. Providing a sample allows one to quickly make a successful API call. // It also allows for code generation directly from the CURL, Postman collection, or raw request/response, // and it tends to answer all questions about the format/structure of a request that, suprisingly, // remain ambiguous or not obvious in other forms of documentation. Dim req As New Chilkat.HttpRequest req.AddParam "grant_type","client_credentials" // Use your actual client ID and client secret... req.AddParam "client_id","d0394a9f-0607-40de-a978-2d3eb8375b04" req.AddParam "client_secret","6d62315e-d65a-4e41-9112-4195ea834edf" req.AddHeader "posserial","1234567899" req.AddHeader "pososversion","os" req.AddHeader "posmodelframework","1" req.AddHeader "presharedkey","03ac674216f3e1..." // When writing this example, the documentation at https://sdk.invoicing.eta.gov.eg/ereceiptapi/01-authenticate-pos/ // shows us the HTTP verb and path (POST /connect/token), however, // we don't see the actual domain where the request is to be sent. // What are the endpoints??? // It took some searching, but we found some endpoints here: https://sdk.invoicing.eta.gov.eg/faq/ // It's not immediately apparent which endpoint is to be used with a given API call. // Why not just include the endpoint in the documentation for each REST API call? // Endpoints are literally the #1 thing that needs to be known. // They can't just be buried in a FAQ. They should be up-front and obvious. // // So.. we're guessing the endpoint is likely "https://invoicing.eta.gov.eg/connect/token" Dim resp As Chilkat.HttpResponse resp = http.PostUrlEncoded("https://invoicing.eta.gov.eg/connect/token",req) If (http.LastMethodSuccess = False) Then System.DebugLog(http.LastErrorText) Return End If Dim sbResponseBody As New Chilkat.StringBuilder success = resp.GetBodySb(sbResponseBody) Dim jResp As New Chilkat.JsonObject success = jResp.LoadSb(sbResponseBody) jResp.EmitCompact = False System.DebugLog("Response Body:") System.DebugLog(jResp.Emit()) Dim respStatusCode As Int32 respStatusCode = resp.StatusCode System.DebugLog("Response Status Code = " + Str(respStatusCode)) If (respStatusCode >= 400) Then System.DebugLog("Response Header:") System.DebugLog(resp.Header) System.DebugLog("Failed.") Return End If // If successful, the OAuth2 access token JSON looks like this: // { // "token_type": "Bearer", // "access_token": "eyJraW......R2sbqrY", // "expires_in": "3600", // "scope": "..." // } Dim token_type As String token_type = jResp.StringOf("token_type") Dim access_token As String access_token = jResp.StringOf("access_token") Dim expires_in As String expires_in = jResp.StringOf("expires_in") Dim scope As String scope = jResp.StringOf("scope") |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.