Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) Xero Build Hashtable of Account Codes

To create a new account, a unique and unused account Code would need to be selected. How do we know what account Codes already exist? One way of finding out is to download the complete set of Accounts every time. Another way is to download once, and keep a local hash table of the account Codes. This makes it possible to find a new and unused Code without having to continually fetch data from the Xero server.

Note: Requires Chilkat v9.5.0.64 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vSbXml
    Handle hoSbXml
    Handle hoHtAccounts
    Boolean iBAutoTrim
    Handle hoXml
    Integer iNumAccounts
    Integer i
    String sHashKey
    String sNotUsed
    Variant vHtXmlSb
    Handle hoHtXmlSb
    String sTemp1
    Integer iTemp1

    // 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.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // 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.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
    If (Not(IsComObjectCreated(hoSbXml))) Begin
        Send CreateComObject of hoSbXml
    End
    Get pvComObject of hoSbXml to vSbXml
    Get ComFullRequestNoBodySb Of hoRest "GET" "/api.xro/2.0/Accounts" vSbXml To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // A 200 response is expected for actual success.
    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComGetAsString Of hoSbXml To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Iterate over the accounts, and build a Hashtable where the
    // key is the account Code, and the value is the XML record for the account.
    Get Create (RefClass(cComChilkatHashtable)) To hoHtAccounts
    If (Not(IsComObjectCreated(hoHtAccounts))) Begin
        Send CreateComObject of hoHtAccounts
    End

    Move False To iBAutoTrim
    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get pvComObject of hoSbXml to vSbXml
    Get ComLoadSb Of hoXml vSbXml iBAutoTrim To iSuccess
    Set ComEmitXmlDecl Of hoXml To False
    Set ComEmitCompact Of hoXml To True

    // How many accounts exist?
    Get ComNumChildrenAt Of hoXml "Accounts" To iNumAccounts
    Showln "numAccounts = " iNumAccounts

    Move 0 To i
    While (i < iNumAccounts)
        Set ComI Of hoXml To i
        Get ComGetChildContent Of hoXml "Accounts|Account[i]|Code" To sHashKey
        // Update the xml object's internal reference to the i'th account record.
        Get ComChilkatPath Of hoXml "Accounts|Account[i]|$" To sNotUsed

        Showln "hash key = " sHashKey
        If (i < 5) Begin
            // Show a few of the values..
            Get ComGetXml Of hoXml To sTemp1
            Showln sTemp1
        End

        Get ComGetXml Of hoXml To sTemp1
        Get ComAddStr Of hoHtAccounts sHashKey sTemp1 To iSuccess

        // Update the xml object's internal reference to the XML root node.
        Send ComGetRoot2 To hoXml
        Move i + 1 To i
    Loop

    // At this point the Hashtable is built.
    // Save the Hashtable to a file.  This will be used in subsequent requests
    // when we need to find a unique/unused Code, or if we want to get
    // the account information from the local hash table.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoHtXmlSb
    If (Not(IsComObjectCreated(hoHtXmlSb))) Begin
        Send CreateComObject of hoHtXmlSb
    End
    Get pvComObject of hoHtXmlSb to vHtXmlSb
    Get ComToXmlSb Of hoHtAccounts vHtXmlSb To iSuccess
    Get ComWriteFile Of hoHtXmlSb "qa_cache/xero_accounts_by_code.xml" "utf-8" False To iSuccess

    Showln "success = " iSuccess


End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.