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) eBay -- Download Data using FileTransferService

Demonstrates how to download a data file using the eBay File Transfer API.

Note: This example requires Chilkat v9.5.0.67 or later.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
string ls_AccessToken
oleobject loo_Http
oleobject loo_Req
oleobject loo_Xml
oleobject loo_Resp
integer li_StatusCode
oleobject loo_ResponseBody
oleobject loo_Mime
integer li_Success
oleobject loo_Part0
string ls_DownloadResponseXml
oleobject loo_XmlResp
oleobject loo_Part1
oleobject loo_ZipData
oleobject loo_SbContentType
oleobject loo_XmlFromZip
oleobject loo_Gzip
oleobject loo_Zip
oleobject loo_Entry

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// Use a previously obtained access token.  The token should look something like this:
// "AgAAAA**AQA ..."
ls_AccessToken = "EBAY_ACCESS_TOKEN"

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat_9_5_0.HttpRequest")

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/FileTransferService"
loo_Req.ContentType = "application/xml"

// Build the XML body for the request.
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_Xml.Tag = "downloadFileRequest"
loo_Xml.AddAttribute("xmlns","http://www.ebay.com/marketplace/services")
loo_Xml.UpdateChildContent("taskReferenceId","50013004806")
loo_Xml.UpdateChildContent("fileReferenceId","50015579016")

loo_Req.LoadBodyFromString(loo_Xml.GetXml(),"utf-8")

// The XML body looks like this:

// 	<?xml version="1.0" encoding="UTF-8"?>
// 	<downloadFileRequest xmlns="http://www.ebay.com/marketplace/services">
// 	<taskReferenceId>50013004806</taskReferenceId>
// 	<fileReferenceId>50015579016</fileReferenceId>
// 	</downloadFileRequest>

loo_Req.AddHeader("X-EBAY-SOA-OPERATION-NAME","downloadFile")
loo_Req.AddHeader("X-EBAY-SOA-SECURITY-TOKEN",ls_AccessToken)

loo_Resp = loo_Http.SynchronousRequest("storage.sandbox.ebay.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    destroy loo_Xml
    return
end if

li_StatusCode = loo_Resp.StatusCode
Write-Debug "Response status code = " + string(li_StatusCode)

loo_ResponseBody = create oleobject
li_rc = loo_ResponseBody.ConnectToNewObject("Chilkat_9_5_0.BinData")

loo_Resp.GetBodyBd(loo_ResponseBody)
destroy loo_Resp

// We can save the response body to a file for examination if we get an unanticipated response.  
// (It's binary, so it won't open well in a text editor.)
loo_ResponseBody.WriteFile("qa_output/response.mime")

if li_StatusCode <> 200 then
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Req
    destroy loo_Xml
    destroy loo_ResponseBody
    return
end if

// The response body looks like this:

// 	--MIMEBoundaryurn_uuid_2B668636C1E17A4D4114925305818684241
// 	Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
// 	Content-Transfer-Encoding: binary
// 	Content-ID: <0.urn:uuid:2B668636C1E17A4D4114925305818684242>
// 
// 	<?xml version='1.0' encoding='UTF-8'?>
// 	<downloadFileResponse xmlns="http://www.ebay.com/marketplace/services">
// 	<ack>Success</ack>
// 	<version>1.1.0</version>
// 	<timestamp>2017-04-18T15:49:41.868Z</timestamp>
// 	<fileAttachment>
// 	    <Size>587</Size>
// 	    <Data>
//                 <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:A37C3C73E994C267F11492530585522"/>
// 	    </Data>
// 	</fileAttachment>
// 	</downloadFileResponse>
// 	--MIMEBoundaryurn_uuid_2B668636C1E17A4D4114925305818684241
// 	Content-Type: application/zip
// 	Content-Transfer-Encoding: binary
// 	Content-ID: <urn:uuid:A37C3C73E994C267F11492530585522>
// 
// 	<the binary bytes of the zip start here...>
// 

// Load the binary response into a MIME object.
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat_9_5_0.Mime")

li_Success = loo_Mime.LoadMimeBd(loo_ResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Http
    destroy loo_Req
    destroy loo_Xml
    destroy loo_ResponseBody
    destroy loo_Mime
    return
end if

// Make sure we have 2 sub-parts.  The 1st sub-part is the XML response, the 2nd sub-part
// is the zip containing the data.

// Note: The 2nd sub-part can be a "zip" or "gzip".  These are two different file formats.
// A zip is indicated with a Content-Type header equal to "application/zip",
// whereas a gzip is indicated with a Content-Type header equal to "application/x-gzip"
if loo_Mime.NumParts <> 2 then
    Write-Debug "Expected the MIME to have 2 parts."
    Write-Debug "NumParts = " + string(loo_Mime.NumParts)
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Req
    destroy loo_Xml
    destroy loo_ResponseBody
    destroy loo_Mime
    return
end if

// Get the XML from the 1st MIME sub-part.
loo_Part0 = loo_Mime.GetPart(0)
ls_DownloadResponseXml = loo_Part0.GetBodyDecoded()
loo_XmlResp = create oleobject
li_rc = loo_XmlResp.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_XmlResp.LoadXml(ls_DownloadResponseXml)
Write-Debug "Download Response XML:"
Write-Debug loo_XmlResp.GetXml()
destroy loo_Part0

Write-Debug "----"

// Now get the zip from the second part (index=1), unzip, and examine..
loo_Part1 = loo_Mime.GetPart(1)
loo_ZipData = create oleobject
li_rc = loo_ZipData.ConnectToNewObject("Chilkat_9_5_0.BinData")

// This example requires Chilkat v9.5.0.67 or later.
// The GetBodyBd method was added in v9.5.0.67.
loo_Part1.GetBodyBd(loo_ZipData)

// Check to see if we have a zip or gzip.
loo_SbContentType = create oleobject
li_rc = loo_SbContentType.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbContentType.Append(loo_Part1.ContentType)
destroy loo_Part1

loo_XmlFromZip = create oleobject
li_rc = loo_XmlFromZip.ConnectToNewObject("Chilkat_9_5_0.Xml")

if loo_SbContentType.Contains("gzip",0) = 1 then
    // This is a gzip compressed file.
    loo_Gzip = create oleobject
    li_rc = loo_Gzip.ConnectToNewObject("Chilkat_9_5_0.Gzip")

    // in-place uncompress the data.
    // Note: The UncompressBd method was added in Chilkat v9.5.0.67
    li_Success = loo_Gzip.UncompressBd(loo_ZipData)
    if li_Success <> 1 then
        Write-Debug loo_Gzip.LastErrorText
        destroy loo_Http
        destroy loo_Req
        destroy loo_Xml
        destroy loo_ResponseBody
        destroy loo_Mime
        destroy loo_XmlResp
        destroy loo_ZipData
        destroy loo_SbContentType
        destroy loo_XmlFromZip
        destroy loo_Gzip
        return
    end if

    loo_XmlFromZip.LoadXml(loo_ZipData.GetString("utf-8"))

else
    // This is a zip archive.

    // Load the body into a Zip object.
    loo_Zip = create oleobject
    li_rc = loo_Zip.ConnectToNewObject("Chilkat_9_5_0.Zip")

    li_Success = loo_Zip.OpenBd(loo_ZipData)
    if li_Success <> 1 then
        Write-Debug loo_Zip.LastErrorText
        destroy loo_Http
        destroy loo_Req
        destroy loo_Xml
        destroy loo_ResponseBody
        destroy loo_Mime
        destroy loo_XmlResp
        destroy loo_ZipData
        destroy loo_SbContentType
        destroy loo_XmlFromZip
        destroy loo_Gzip
        destroy loo_Zip
        return
    end if

    // Save the .zip to a file (so we can examine it for debugging if something is not as expected)
    loo_ZipData.WriteFile("qa_output/ebay_data.zip")

    // The zip should contain a single XML file.
    if loo_Zip.NumEntries <> 1 then
        Write-Debug "Expected the .zip to have 1 entry."
        Write-Debug "NumEntries = " + string(loo_Zip.NumEntries)
        Write-Debug "Failed."
        destroy loo_Http
        destroy loo_Req
        destroy loo_Xml
        destroy loo_ResponseBody
        destroy loo_Mime
        destroy loo_XmlResp
        destroy loo_ZipData
        destroy loo_SbContentType
        destroy loo_XmlFromZip
        destroy loo_Gzip
        destroy loo_Zip
        return
    end if

    loo_Entry = loo_Zip.GetEntryByIndex(0)

    loo_XmlFromZip.LoadXml(loo_Entry.UnzipToString(0,"utf-8"))
    destroy loo_Entry
end if

Write-Debug "XML contained in the zip:"
Write-Debug loo_XmlFromZip.GetXml()
Write-Debug "----"

Write-Debug "Success."


destroy loo_Http
destroy loo_Req
destroy loo_Xml
destroy loo_ResponseBody
destroy loo_Mime
destroy loo_XmlResp
destroy loo_ZipData
destroy loo_SbContentType
destroy loo_XmlFromZip
destroy loo_Gzip
destroy loo_Zip

 

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