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

DataFlex 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
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

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

 

 

 

(DataFlex) eBay -- Upload Bulk Data using FileTransferService

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    String sAccessToken
    Handle hoHttp
    String sApiCall
    String sFileAttachmentUuid
    String sXmlUuid
    Variant vReq
    Handle hoReq
    Handle hoSbContentType
    Integer iReplaceCount
    String sPathToFileOnDisk1
    Boolean iSuccess
    String sPathToFileOnDisk2
    Variant vResp
    Handle hoResp
    Handle hoXml
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // 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 ..."
    Move "EBAY_ACCESS_TOKEN" To sAccessToken

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Move "uploadFile" To sApiCall
    Move "<urn:uuid:bb47b86a237311e793ae92361f002671>" To sFileAttachmentUuid
    Move "<urn:uuid:bb47b766237311e793ae92361f002671>" To sXmlUuid

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End

    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/FileTransferService"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbContentType
    If (Not(IsComObjectCreated(hoSbContentType))) Begin
        Send CreateComObject of hoSbContentType
    End
    Get ComAppend Of hoSbContentType 'multipart/related; type="application/xop+xml"; start="XMLUUID"; start-info="text/xml"' To iSuccess
    Get ComReplace Of hoSbContentType "XMLUUID" sXmlUuid To iReplaceCount
    Get ComGetAsString Of hoSbContentType To sTemp1
    Set ComContentType Of hoReq To sTemp1

    Send ComAddHeader To hoReq "X-EBAY-SOA-SERVICE-NAME" "FileTransferService"
    Send ComAddHeader To hoReq "X-EBAY-SOA-OPERATION-NAME" sApiCall
    Send ComAddHeader To hoReq "X-EBAY-SOA-SECURITY-TOKEN" sAccessToken
    Send ComAddHeader To hoReq "X-EBAY-SOA-REQUEST-DATA-FORMAT" "XML"
    Send ComAddHeader To hoReq "X-EBAY-SOA-RESPONSE-DATA-FORMAT" "XML"
    Send ComAddHeader To hoReq "User-Agent" "AnythingYouWant"

    Move "qa_data/ebay/uploadFileRequest.xml" To sPathToFileOnDisk1
    Get ComAddFileForUpload Of hoReq "uploadFileRequest.xml" sPathToFileOnDisk1 To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoReq To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move "qa_data/ebay/BulkDataExchangeRequests.gz" To sPathToFileOnDisk2
    Get ComAddFileForUpload Of hoReq "BulkDataExchangeRequests.gz" sPathToFileOnDisk2 To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoReq To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Add sub-headers for each file in the request.
    Get ComAddSubHeader Of hoReq 0 "Content-Type" 'application/xop+xml; charset=UTF-8; type="text/xml"' To iSuccess
    Get ComAddSubHeader Of hoReq 0 "Content-Transfer-Encoding" "binary" To iSuccess
    Get ComAddSubHeader Of hoReq 0 "Content-ID" sXmlUuid To iSuccess
    Get ComAddSubHeader Of hoReq 1 "Content-Type" "application/octet-stream" To iSuccess
    Get ComAddSubHeader Of hoReq 1 "Content-Transfer-Encoding" "binary" To iSuccess
    Get ComAddSubHeader Of hoReq 1 "Content-ID" sFileAttachmentUuid To iSuccess

    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "storage.sandbox.ebay.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "Response status code = " iTemp1

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoadXml Of hoXml sTemp1 To iSuccess

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComGetXml Of hoXml To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

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

    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    // Get the "ack" to see if it's "Failure" or "Success"
    Get ComChildContentMatches Of hoXml "ack" "Success" False To bTemp1
    If (bTemp1) Begin
        Showln "Success."
    End
    Else Begin
        Showln "Failure."
    End

    Send Destroy of hoResp


End_Procedure

 

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