Unicode C++
Unicode C++
eBay -- Upload Bulk Data using FileTransferService
See more eBay Examples
Demonstrates how to upload your data file using the eBay File Transfer API.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>
#include <CkXmlW.h>
void ChilkatSample(void)
{
bool success = false;
// 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 ..."
const wchar_t *accessToken = L"EBAY_ACCESS_TOKEN";
CkHttpW http;
const wchar_t *apiCall = L"uploadFile";
const wchar_t *fileAttachmentUuid = L"<urn:uuid:bb47b86a237311e793ae92361f002671>";
const wchar_t *xmlUuid = L"<urn:uuid:bb47b766237311e793ae92361f002671>";
CkHttpRequestW req;
req.put_HttpVerb(L"POST");
req.put_Path(L"/FileTransferService");
CkStringBuilderW sbContentType;
sbContentType.Append(L"multipart/related; type=\"application/xop+xml\"; start=\"XMLUUID\"; start-info=\"text/xml\"");
int replaceCount = sbContentType.Replace(L"XMLUUID",xmlUuid);
req.put_ContentType(sbContentType.getAsString());
req.AddHeader(L"X-EBAY-SOA-SERVICE-NAME",L"FileTransferService");
req.AddHeader(L"X-EBAY-SOA-OPERATION-NAME",apiCall);
req.AddHeader(L"X-EBAY-SOA-SECURITY-TOKEN",accessToken);
req.AddHeader(L"X-EBAY-SOA-REQUEST-DATA-FORMAT",L"XML");
req.AddHeader(L"X-EBAY-SOA-RESPONSE-DATA-FORMAT",L"XML");
req.AddHeader(L"User-Agent",L"AnythingYouWant");
const wchar_t *pathToFileOnDisk1 = L"qa_data/ebay/uploadFileRequest.xml";
success = req.AddFileForUpload(L"uploadFileRequest.xml",pathToFileOnDisk1);
if (success == false) {
wprintf(L"%s\n",req.lastErrorText());
return;
}
const wchar_t *pathToFileOnDisk2 = L"qa_data/ebay/BulkDataExchangeRequests.gz";
success = req.AddFileForUpload(L"BulkDataExchangeRequests.gz",pathToFileOnDisk2);
if (success == false) {
wprintf(L"%s\n",req.lastErrorText());
return;
}
// Add sub-headers for each file in the request.
req.AddSubHeader(0,L"Content-Type",L"application/xop+xml; charset=UTF-8; type=\"text/xml\"");
req.AddSubHeader(0,L"Content-Transfer-Encoding",L"binary");
req.AddSubHeader(0,L"Content-ID",xmlUuid);
req.AddSubHeader(1,L"Content-Type",L"application/octet-stream");
req.AddSubHeader(1,L"Content-Transfer-Encoding",L"binary");
req.AddSubHeader(1,L"Content-ID",fileAttachmentUuid);
CkHttpResponseW resp;
success = http.HttpSReq(L"storage.sandbox.ebay.com",443,true,req,resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"Response status code = %d\n",resp.get_StatusCode());
CkXmlW xml;
xml.LoadXml(resp.bodyStr());
if (resp.get_StatusCode() != 200) {
wprintf(L"%s\n",xml.getXml());
wprintf(L"Failed.\n");
return;
}
// 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>
wprintf(L"%s\n",xml.getXml());
// Get the "ack" to see if it's "Failure" or "Success"
if (xml.ChildContentMatches(L"ack",L"Success",false)) {
wprintf(L"Success.\n");
}
else {
wprintf(L"Failure.\n");
}
}