Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PureBasic Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(PureBasic) eBay -- Upload Bulk Data using FileTransferService

Demonstrates how to upload your data file using the eBay File Transfer API.

Chilkat PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkXml.pb"
IncludeFile "CkHttpRequest.pb"

Procedure ChilkatExample()

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

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    apiCall.s = "uploadFile"
    fileAttachmentUuid.s = "<urn:uuid:bb47b86a237311e793ae92361f002671>"
    xmlUuid.s = "<urn:uuid:bb47b766237311e793ae92361f002671>"

    req.i = CkHttpRequest::ckCreate()
    If req.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpRequest::setCkHttpVerb(req, "POST")
    CkHttpRequest::setCkPath(req, "/FileTransferService")

    sbContentType.i = CkStringBuilder::ckCreate()
    If sbContentType.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkStringBuilder::ckAppend(sbContentType,"multipart/related; type=" + Chr(34) + "application/xop+xml" + Chr(34) + "; start=" + Chr(34) + "XMLUUID" + Chr(34) + "; start-info=" + Chr(34) + "text/xml" + Chr(34))
    replaceCount.i = CkStringBuilder::ckReplace(sbContentType,"XMLUUID",xmlUuid)
    CkHttpRequest::setCkContentType(req, CkStringBuilder::ckGetAsString(sbContentType))

    CkHttpRequest::ckAddHeader(req,"X-EBAY-SOA-SERVICE-NAME","FileTransferService")
    CkHttpRequest::ckAddHeader(req,"X-EBAY-SOA-OPERATION-NAME",apiCall)
    CkHttpRequest::ckAddHeader(req,"X-EBAY-SOA-SECURITY-TOKEN",accessToken)
    CkHttpRequest::ckAddHeader(req,"X-EBAY-SOA-REQUEST-DATA-FORMAT","XML")
    CkHttpRequest::ckAddHeader(req,"X-EBAY-SOA-RESPONSE-DATA-FORMAT","XML")
    CkHttpRequest::ckAddHeader(req,"User-Agent","AnythingYouWant")

    pathToFileOnDisk1.s = "qa_data/ebay/uploadFileRequest.xml"
    success.i = CkHttpRequest::ckAddFileForUpload(req,"uploadFileRequest.xml",pathToFileOnDisk1)
    If success <> 1
        Debug CkHttpRequest::ckLastErrorText(req)
        CkHttp::ckDispose(http)
        CkHttpRequest::ckDispose(req)
        CkStringBuilder::ckDispose(sbContentType)
        ProcedureReturn
    EndIf

    pathToFileOnDisk2.s = "qa_data/ebay/BulkDataExchangeRequests.gz"
    success = CkHttpRequest::ckAddFileForUpload(req,"BulkDataExchangeRequests.gz",pathToFileOnDisk2)
    If success <> 1
        Debug CkHttpRequest::ckLastErrorText(req)
        CkHttp::ckDispose(http)
        CkHttpRequest::ckDispose(req)
        CkStringBuilder::ckDispose(sbContentType)
        ProcedureReturn
    EndIf

    ;  Add sub-headers for each file in the request.
    CkHttpRequest::ckAddSubHeader(req,0,"Content-Type","application/xop+xml; charset=UTF-8; type=" + Chr(34) + "text/xml" + Chr(34))
    CkHttpRequest::ckAddSubHeader(req,0,"Content-Transfer-Encoding","binary")
    CkHttpRequest::ckAddSubHeader(req,0,"Content-ID",xmlUuid)
    CkHttpRequest::ckAddSubHeader(req,1,"Content-Type","application/octet-stream")
    CkHttpRequest::ckAddSubHeader(req,1,"Content-Transfer-Encoding","binary")
    CkHttpRequest::ckAddSubHeader(req,1,"Content-ID",fileAttachmentUuid)

    resp.i = CkHttp::ckSynchronousRequest(http,"storage.sandbox.ebay.com",443,1,req)
    If CkHttp::ckLastMethodSuccess(http) <> 1
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkHttpRequest::ckDispose(req)
        CkStringBuilder::ckDispose(sbContentType)
        ProcedureReturn
    EndIf

    Debug "Response status code = " + Str(CkHttpResponse::ckStatusCode(resp))

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::ckLoadXml(xml,CkHttpResponse::ckBodyStr(resp))

    If CkHttpResponse::ckStatusCode(resp) <> 200
        Debug CkXml::ckGetXml(xml)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkHttpRequest::ckDispose(req)
        CkStringBuilder::ckDispose(sbContentType)
        CkXml::ckDispose(xml)
        ProcedureReturn
    EndIf

    ;  We still may have a failure.  The XML needs to be checked.
    ;  A failed response might look like this:

    ;  	<?xml version="1.0" encoding="UTF-8" ?>
    ;  	<uploadFileResponse xmlns="http://www.ebay.com/marketplace/services">
    ;  	    <ack>Failure</ack>
    ;  	    <errorMessage>
    ;  	        <error>
    ;  	            <errorId>1</errorId>
    ;  	            <domain>Marketplace</domain>
    ;  	            <severity>Error</severity>
    ;  	            <category>Application</category>
    ;  	            <message>Task Reference Id is invalid</message>
    ;  	            <subdomain>FileTransfer</subdomain>
    ;  	        </error>
    ;  	    </errorMessage>
    ;  	    <version>1.1.0</version>
    ;  	    <timestamp>2017-04-18T01:05:27.475Z</timestamp>
    ;  	</uploadFileResponse>

    ;  A successful response looks like this:

    ;  	<?xml version="1.0" encoding="UTF-8" ?>
    ;  	<uploadFileResponse xmlns="http://www.ebay.com/marketplace/services">
    ;  	    <ack>Success</ack>
    ;  	    <version>1.1.0</version>
    ;  	    <timestamp>2017-04-18T01:22:47.853Z</timestamp>
    ;  	</uploadFileResponse>

    Debug CkXml::ckGetXml(xml)

    ;  Get the "ack" to see if it's "Failure" or "Success"
    If CkXml::ckChildContentMatches(xml,"ack","Success",0)
        Debug "Success."
    Else
        Debug "Failure."
    EndIf

    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkHttpRequest::ckDispose(req)
    CkStringBuilder::ckDispose(sbContentType)
    CkXml::ckDispose(xml)


    ProcedureReturn
EndProcedure

 

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