AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oRest = ObjCreate("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
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("mws.amazonservices.com",$iPort,$bTls,$bAutoReconnect)
$oRest.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.
$oRest.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.
$oPdfData = ObjCreate("Chilkat.BinData")
$bSuccess = $oPdfData.LoadFile("qa_data/pdf/sample.pdf")
; Get the MD5 hash of the PDF data.
$oCrypt = ObjCreate("Chilkat.Crypt2")
$oCrypt.HashAlgorithm = "md5"
$oCrypt.EncodingMode = "base64"
Local $sMd5Hash = $oCrypt.HashBdENC($oPdfData)
$oRest.AddQueryParam("AWSAccessKeyId","0PB842ExampleN4ZTR2")
$oRest.AddQueryParam("Action","SubmitFeed")
$oRest.AddQueryParam("FeedType","_UPLOAD_VAT_INVOICE_")
$oRest.AddQueryParam("MWSAuthToken","EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE")
$oRest.AddQueryParam("MarketplaceIdList.Id.1","ATVExampleDER")
$oRest.AddQueryParam("SellerId","A1XExample5E6")
$oRest.AddQueryParam("ContentMD5Value",$sMd5Hash)
$oRest.AddQueryParam("SignatureMethod","HmacSHA256")
$oRest.AddQueryParam("SignatureVersion","2")
$oRest.AddQueryParam("Version","2009-01-01")
; Add the MWS Signature param. (Also adds the Timestamp parameter using the curent system date/time.)
$oRest.AddMwsSignature("POST","/Feeds/2009-01-01","mws.amazonservices.com","YOUR_MWS_SECRET_ACCESS_KEY_ID")
$oRest.AddHeader("Content-Type","application/octet-stream")
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestBd("POST","/Feeds/2009-01-01",$oPdfData,$oSbResponseBody)
If ($oRest.LastMethodSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
; Examine the request/response to see what happened.
ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF)
ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF)
ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF)
ConsoleWrite("response body: " & $oSbResponseBody.GetAsString() & @CRLF)
ConsoleWrite("---" & @CRLF)
ConsoleWrite("LastRequestStartLine: " & $oRest.LastRequestStartLine & @CRLF)
ConsoleWrite("LastRequestHeader: " & $oRest.LastRequestHeader & @CRLF)
EndIf
; Examine the XML returned in the response body.
ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
ConsoleWrite("----" & @CRLF)
ConsoleWrite("Success." & @CRLF)