Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) MyInvois Malaysia Submit DocumentSee more Malaysia MyInvois ExamplesDemonstrates how to submit a document to MyInvois. For more information, see https://sdk.myinvois.hasil.gov.my/einvoicingapi/02-submit-documents/
integer li_rc oleobject loo_Http integer li_Success oleobject loo_SbXmlDoc string ls_Sha256 oleobject loo_SbEncoded oleobject loo_Json oleobject loo_Resp // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // The following JSON is sent in the request body. // { // "documents": [ // { // "format": "XML", // "documentHash": "<SHA256_hash_of_document>", // "codeNumber": "INV12345", // "document": "<Document_encoded_in_Base64>" // } // ] // } // Load the document to be sent. loo_SbXmlDoc = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbXmlDoc.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_SbXmlDoc.LoadFile("c:/invoices/invoice1.xml","utf-8") // The MyInvois online documentation neglects to tell us the encoding of the documentHash. // Should it be base64? Or hex? We can only guess. MyInvois provides no samples, // and omits these crucial details which are needed for actual implementation. // // *** Note: It was confirmed that "hex" is the encoding that is needed. ls_Sha256 = loo_SbXmlDoc.GetHash("sha256","hex","utf-8") loo_SbEncoded = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbEncoded.ConnectToNewObject("Chilkat.StringBuilder") loo_SbEncoded.AppendSb(loo_SbXmlDoc) loo_SbEncoded.Encode("base64","utf-8") loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("documents[0].format","XML") loo_Json.UpdateString("documents[0].documentHash",ls_Sha256) loo_Json.UpdateString("documents[0].codeNumber","INV12345") loo_Json.UpdateSb("documents[0].document",loo_SbEncoded) // Adds the "Authorization: Bearer <access_token>" header. loo_Http.AuthToken = "<access_token>" loo_Resp = loo_Http.PostJson3("https://preprod-api.myinvois.hasil.gov.my/api/v1.0/documentsubmissions","application/json",loo_Json) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_SbXmlDoc destroy loo_SbEncoded destroy loo_Json return end if Write-Debug "response status code = " + string(loo_Resp.StatusCode) Write-Debug loo_Resp.BodyStr destroy loo_Resp destroy loo_Http destroy loo_SbXmlDoc destroy loo_SbEncoded destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.