Visual FoxPro
Visual FoxPro
Xero Export Accounts to CSV
Demonstrates how to export Accounts data to a CSV.Note: Requires Chilkat v9.5.0.64 or greater.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL loSbXml
LOCAL loCsv
LOCAL lnBAutoTrim
LOCAL loXml
LOCAL lnNumAccounts
LOCAL i
lnSuccess = 0
* 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.
loRest = CreateObject('Chilkat.Rest')
* 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..
* Get the full list of accounts.
loSbXml = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/api.xro/2.0/Accounts",loSbXml)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loSbXml
CANCEL
ENDIF
* A 200 response is expected for actual success.
IF (loRest.ResponseStatusCode <> 200) THEN
? loSbXml.GetAsString()
RELEASE loRest
RELEASE loSbXml
CANCEL
ENDIF
* Build a CSV containing a few Account fields.
loCsv = CreateObject('Chilkat.Csv')
loCsv.HasColumnNames = 1
loCsv.SetColumnName(0,"AccountID")
loCsv.SetColumnName(1,"Name")
loCsv.SetColumnName(2,"Code")
loCsv.SetColumnName(3,"EnablePaymentsToAccount")
* Iterate over the accounts and build the CSV.
lnBAutoTrim = 0
loXml = CreateObject('Chilkat.Xml')
loXml.LoadSb(loSbXml,lnBAutoTrim)
lnNumAccounts = loXml.NumChildrenAt("Accounts")
i = 0
DO WHILE i < lnNumAccounts
loXml.I = i
loCsv.SetCellByName(i,"AccountID",loXml.GetChildContent("Accounts|Account[i]|AccountID"))
loCsv.SetCellByName(i,"Name",loXml.GetChildContent("Accounts|Account[i]|Name"))
loCsv.SetCellByName(i,"Code",loXml.GetChildContent("Accounts|Account[i]|Code"))
loCsv.SetCellByName(i,"EnablePaymentsToAccount",loXml.GetChildContent("Accounts|Account[i]|EnablePaymentsToAccount"))
i = i + 1
ENDDO
* Examine the CSV.
? loCsv.SaveToString()
* Save the CSV to a file.
loCsv.SaveFile("qa_output/xero_accounts.csv")
RELEASE loRest
RELEASE loSbXml
RELEASE loCsv
RELEASE loXml