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) Xero Get File Content (Files API)Demonstrates how to download the content of a Xero file. Note: This example requires Chilkat v9.5.0.64 or greater.
integer li_rc oleobject loo_Rest integer li_Success string ls_FileID oleobject loo_SbPath integer li_NumReplaced oleobject loo_JpgData oleobject loo_SbErrorText // Note: Requires Chilkat v9.5.0.64 or greater. // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Rest = create oleobject // Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest") if li_rc < 0 then destroy loo_Rest MessageBox("Error","Connecting to COM object failed") return end if // Before sending REST API calls, the REST object needs to be // initialized for OAuth1. // See Xero 2-Legged OAuth1 Setup for sample code. // Assuming the REST object's OAuth1 authenticator is setup, and the initial // connection was made, we may now send REST HTTP requests.. // ------------------------------------------------------------------------------ ls_FileID = "f042e9a3-a31d-4595-b8b3-6030ea6084bb" loo_SbPath = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbPath.ConnectToNewObject("Chilkat.StringBuilder") loo_SbPath.Append("/files.xro/1.0/Files/{FileId}/Content") li_NumReplaced = loo_SbPath.Replace("{FileId}",ls_FileID) loo_JpgData = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_JpgData.ConnectToNewObject("Chilkat.BinData") li_Success = loo_Rest.FullRequestNoBodyBd("GET",loo_SbPath.GetAsString(),loo_JpgData) if li_Success <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_Rest destroy loo_SbPath destroy loo_JpgData return end if // A 200 response is expected for actual success. // If we don't get a 200 response, then the response body was not actually // the file data, but it was text containing error information. if loo_Rest.ResponseStatusCode <> 200 then loo_SbErrorText = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbErrorText.ConnectToNewObject("Chilkat.StringBuilder") loo_SbErrorText.AppendBd(loo_JpgData,"utf-8",0,0) Write-Debug loo_SbErrorText.GetAsString() Write-Debug "-- Failed." destroy loo_Rest destroy loo_SbPath destroy loo_JpgData destroy loo_SbErrorText return end if // Save to a local file. li_Success = loo_JpgData.WriteFile("qa_output/xero_penguins.jpg") if li_Success <> 1 then Write-Debug "Failed to save to local file." end if Write-Debug "Xero Get File was Successful." destroy loo_Rest destroy loo_SbPath destroy loo_JpgData destroy loo_SbErrorText |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.