Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loPdfData
LOCAL loCrypt
LOCAL lcMd5Hash
LOCAL loSbResponseBody

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loRest = CreateObject('Chilkat.Rest')

* 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

lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("mws.amazonservices.com",lnPort,lnBTls,lnBAutoReconnect)

loRest.Host = "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.
loRest.AddQueryParam("FeedOptions","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.
loPdfData = CreateObject('Chilkat.BinData')
lnSuccess = loPdfData.LoadFile("qa_data/pdf/sample.pdf")

* Get the MD5 hash of the PDF data.
loCrypt = CreateObject('Chilkat.Crypt2')
loCrypt.HashAlgorithm = "md5"
loCrypt.EncodingMode = "base64"
lcMd5Hash = loCrypt.HashBdENC(loPdfData)

loRest.AddQueryParam("AWSAccessKeyId","0PB842ExampleN4ZTR2")
loRest.AddQueryParam("Action","SubmitFeed")
loRest.AddQueryParam("FeedType","_UPLOAD_VAT_INVOICE_")
loRest.AddQueryParam("MWSAuthToken","EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE")

loRest.AddQueryParam("MarketplaceIdList.Id.1","ATVExampleDER")
loRest.AddQueryParam("SellerId","A1XExample5E6")
loRest.AddQueryParam("ContentMD5Value",lcMd5Hash)
loRest.AddQueryParam("SignatureMethod","HmacSHA256")
loRest.AddQueryParam("SignatureVersion","2")
loRest.AddQueryParam("Version","2009-01-01")

* Add the MWS Signature param.  (Also adds the Timestamp parameter using the curent system date/time.)
loRest.AddMwsSignature("POST","/Feeds/2009-01-01","mws.amazonservices.com","YOUR_MWS_SECRET_ACCESS_KEY_ID")

loRest.AddHeader("Content-Type","application/octet-stream")
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestBd("POST","/Feeds/2009-01-01",loPdfData,loSbResponseBody)
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loPdfData
    RELEASE loCrypt
    RELEASE loSbResponseBody
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    * Examine the request/response to see what happened.
    ? "response status code = " + STR(loRest.ResponseStatusCode)
    ? "response status text = " + loRest.ResponseStatusText
    ? "response header: " + loRest.ResponseHeader
    ? "response body: " + loSbResponseBody.GetAsString()
    ? "---"
    ? "LastRequestStartLine: " + loRest.LastRequestStartLine
    ? "LastRequestHeader: " + loRest.LastRequestHeader
ENDIF

* Examine the XML returned in the response body.
? loSbResponseBody.GetAsString()
? "----"
? "Success."

RELEASE loRest
RELEASE loPdfData
RELEASE loCrypt
RELEASE loSbResponseBody