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

PowerBuilder 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

 

 

 

(PowerBuilder) Xero API through an SOCKS Proxy

This example demonstrates connecting through a SOCKS proxy w/ 2-legged OAuth for a Xero private application.

This example requires Chilkat v9.5.0.64 or later

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Rest
oleobject loo_Socket
integer li_BTls
integer li_Port
integer li_MaxWaitMs
integer li_Success
string ls_ConsumerKey
string ls_ConsumerSecret
oleobject loo_Pfx
oleobject loo_PrivKeyFromPfx
oleobject loo_PrivKeyFromPem
oleobject loo_Oauth1
oleobject loo_SbXml
integer li_BAutoTrim
oleobject loo_Xml
integer li_RecordCount
integer i

// This example requires Chilkat v9.5.0.64 or later

// This sample code would typically be placed in a subroutine or function
// where the rest object is passed by reference.
// It does the OAuth1 setup and makes the initial connection.
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Connect to the Xero server through an HTTP proxy, and then tell the REST object
// to use the socket connection.
loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat_9_5_0.Socket")

// Set the SOCKS proxy domain or IP address, port, and SOCKS version number (4 or 5)
loo_Socket.SocksHostname = "192.168.1.100"
loo_Socket.SocksPort = 1080
loo_Socket.SocksVersion = 5
// Other properties exist for specifying a SOCKS proxy login and password,
// but these are not used in this example.

// Connect through the SOCKS proxy..
li_BTls = 1
li_Port = 443
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("api.xero.com",li_Port,li_BTls,li_MaxWaitMs)
if li_Success <> 1 then
    Write-Debug "Connect Failure Error Code: " + string(loo_Socket.ConnectFailReason)
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    return
end if

// Use the SOCKS proxied TLS connection:
li_Success = loo_Rest.UseConnection(loo_Socket,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    return
end if

// OK, we're connected.  
// The UseConnection method has an internal reference to the underlying/internal socket.
// The application can does not need to keep its socket object in existence.
// -----------------------------------------------------------------
// Now setup the OAuth1 authenticator..

ls_ConsumerKey = "XERO_PRIVATE_APP_KEY"
ls_ConsumerSecret = "XERO_PRIVATE_APP_SECRET"

// Let's get our private key from our PFX (password protected), or the PEM (unprotected).
// You can decide which to use.  Either is OK, although I would recommend keeping your
// private keys in a PFX and not in an unprotected PEM.
loo_Pfx = create oleobject
li_rc = loo_Pfx.ConnectToNewObject("Chilkat_9_5_0.Pfx")

li_Success = loo_Pfx.LoadPfxFile("qa_data/certs/xero_private_app/public_privatekey.pfx","PFX_PASSWORD")
if li_Success <> 1 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    destroy loo_Pfx
    return
end if

loo_PrivKeyFromPfx = loo_Pfx.GetPrivateKey(0)
if loo_Pfx.LastMethodSuccess <> 1 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    destroy loo_Pfx
    return
end if

// Or we can load from a PEM..
loo_PrivKeyFromPem = create oleobject
li_rc = loo_PrivKeyFromPem.ConnectToNewObject("Chilkat_9_5_0.PrivateKey")

li_Success = loo_PrivKeyFromPem.LoadPemFile("qa_data/certs/xero_private_app/privatekey.pem")
if li_Success <> 1 then
    Write-Debug loo_PrivKeyFromPem.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    destroy loo_Pfx
    destroy loo_PrivKeyFromPem
    return
end if

// Note: There are many other means for loading a private key, including
// from other formats and directly from memory (i.e. not file-based).

loo_Oauth1 = create oleobject
li_rc = loo_Oauth1.ConnectToNewObject("Chilkat_9_5_0.OAuth1")

loo_Oauth1.ConsumerKey = ls_ConsumerKey
loo_Oauth1.ConsumerSecret = ls_ConsumerSecret
loo_Oauth1.Token = ls_ConsumerKey
loo_Oauth1.TokenSecret = ls_ConsumerSecret
loo_Oauth1.SignatureMethod = "RSA-SHA1"
loo_Oauth1.SetRsaKey(loo_PrivKeyFromPfx)
destroy loo_PrivKeyFromPfx

// Install the OAuth1 authenticator.
loo_Rest.SetAuthOAuth1(loo_Oauth1,0)

Write-Debug "OK, the Xero OAuth1 is initialized and the REST object is ready to make REST API calls.."

// -----------------------------------------------------------------
// Make a call to verify that OAuth1 through an HTTP proxy works..

// Get the full list of contacts.
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/api.xro/2.0/Contacts",loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Socket
    destroy loo_Pfx
    destroy loo_PrivKeyFromPem
    destroy loo_Oauth1
    destroy loo_SbXml
    return
end if

// A 200 response is expected for actual success.
if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug loo_SbXml.GetAsString()
    destroy loo_Rest
    destroy loo_Socket
    destroy loo_Pfx
    destroy loo_PrivKeyFromPem
    destroy loo_Oauth1
    destroy loo_SbXml
    return
end if

// Iterate over the contacts..
li_BAutoTrim = 0
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_Xml.LoadSb(loo_SbXml,li_BAutoTrim)
loo_Xml.SaveXml("qa_cache/xero_contacts.xml")

// How many records exist?
li_RecordCount = loo_Xml.NumChildrenAt("Contacts")
Write-Debug "numRecords = " + string(li_RecordCount)

i = 0
do while i < li_RecordCount
    loo_Xml.I = i
    Write-Debug "ContactID: " + loo_Xml.GetChildContent("Contacts|Contact[i]|ContactID")
    i = i + 1
loop


destroy loo_Rest
destroy loo_Socket
destroy loo_Pfx
destroy loo_PrivKeyFromPem
destroy loo_Oauth1
destroy loo_SbXml
destroy loo_Xml

 

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