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 Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(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 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 ..."
    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.