Unicode C
Unicode C
Amazon MWS Upload Invoice
See more Amazon MWS Examples
Demonstrates how to upload an invoice using _UPLOAD_VAT_INVOICE_FeedType to submit an invoice for an order.Chilkat Unicode C Downloads
#include <C_CkRestW.h>
#include <C_CkBinDataW.h>
#include <C_CkCrypt2W.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkRestW rest;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkBinDataW pdfData;
HCkCrypt2W crypt;
const wchar_t *md5Hash;
HCkStringBuilderW sbResponseBody;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
// Connect to the Amazon MWS REST server.
//
// Make sure to connect to the correct Amazon MWS Endpoint, otherwise
// you'll get an HTTP 401 response code.
//
// See Amazon MWS endpoints and MarketplaceId values
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"mws.amazonservices.com",port,bTls,bAutoReconnect);
CkRestW_putHost(rest,L"mws.amazonservices.com");
// MarketplaceList.Id parameter �This should be the marketplace in which the order was placed. Only one marketplace must be used per order.T
// Here are the marketplace ID's
// Spain: A1RKKUPIHCS9HS
// UK: A1F83G8C2ARO7P
// France: A13V1IB3VIYZZH
// Germany: A1PA6795UKMFR9
// Italy: APJ6JRA9NG5V4
// ...
// (See https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html)
// FeedOptions parameter � Seller can input key value pairs to give important metadata along with the PDF invoice.
CkRestW_AddQueryParam(rest,L"FeedOptions",L"metadata:orderid=206-2341234-3455465;metadata:invoicenumber=INT-3431-XJE3;metadata:documenttype=Invoice");
// Load the PDF invoice file that is to be the body of the HTTP POST request.
pdfData = CkBinDataW_Create();
success = CkBinDataW_LoadFile(pdfData,L"qa_data/pdf/sample.pdf");
// Get the MD5 hash of the PDF data.
crypt = CkCrypt2W_Create();
CkCrypt2W_putHashAlgorithm(crypt,L"md5");
CkCrypt2W_putEncodingMode(crypt,L"base64");
md5Hash = CkCrypt2W_hashBdENC(crypt,pdfData);
CkRestW_AddQueryParam(rest,L"AWSAccessKeyId",L"0PB842ExampleN4ZTR2");
CkRestW_AddQueryParam(rest,L"Action",L"SubmitFeed");
CkRestW_AddQueryParam(rest,L"FeedType",L"_UPLOAD_VAT_INVOICE_");
CkRestW_AddQueryParam(rest,L"MWSAuthToken",L"EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE");
CkRestW_AddQueryParam(rest,L"MarketplaceIdList.Id.1",L"ATVExampleDER");
CkRestW_AddQueryParam(rest,L"SellerId",L"A1XExample5E6");
CkRestW_AddQueryParam(rest,L"ContentMD5Value",md5Hash);
CkRestW_AddQueryParam(rest,L"SignatureMethod",L"HmacSHA256");
CkRestW_AddQueryParam(rest,L"SignatureVersion",L"2");
CkRestW_AddQueryParam(rest,L"Version",L"2009-01-01");
// Add the MWS Signature param. (Also adds the Timestamp parameter using the curent system date/time.)
CkRestW_AddMwsSignature(rest,L"POST",L"/Feeds/2009-01-01",L"mws.amazonservices.com",L"YOUR_MWS_SECRET_ACCESS_KEY_ID");
CkRestW_AddHeader(rest,L"Content-Type",L"application/octet-stream");
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestBd(rest,L"POST",L"/Feeds/2009-01-01",pdfData,sbResponseBody);
if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkBinDataW_Dispose(pdfData);
CkCrypt2W_Dispose(crypt);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
if (CkRestW_getResponseStatusCode(rest) != 200) {
// Examine the request/response to see what happened.
wprintf(L"response status code = %d\n",CkRestW_getResponseStatusCode(rest));
wprintf(L"response status text = %s\n",CkRestW_responseStatusText(rest));
wprintf(L"response header: %s\n",CkRestW_responseHeader(rest));
wprintf(L"response body: %s\n",CkStringBuilderW_getAsString(sbResponseBody));
wprintf(L"---\n");
wprintf(L"LastRequestStartLine: %s\n",CkRestW_lastRequestStartLine(rest));
wprintf(L"LastRequestHeader: %s\n",CkRestW_lastRequestHeader(rest));
}
// Examine the XML returned in the response body.
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
wprintf(L"----\n");
wprintf(L"Success.\n");
CkRestW_Dispose(rest);
CkBinDataW_Dispose(pdfData);
CkCrypt2W_Dispose(crypt);
CkStringBuilderW_Dispose(sbResponseBody);
}