Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_PdfData
oleobject loo_Crypt
string ls_Md5Hash
oleobject loo_SbResponseBody

li_Success = 0

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

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("mws.amazonservices.com",li_Port,li_BTls,li_BAutoReconnect)

loo_Rest.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.
loo_Rest.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.
loo_PdfData = create oleobject
li_rc = loo_PdfData.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_PdfData.LoadFile("qa_data/pdf/sample.pdf")

// Get the MD5 hash of the PDF data.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")

loo_Crypt.HashAlgorithm = "md5"
loo_Crypt.EncodingMode = "base64"
ls_Md5Hash = loo_Crypt.HashBdENC(loo_PdfData)

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

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

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

loo_Rest.AddHeader("Content-Type","application/octet-stream")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.FullRequestBd("POST","/Feeds/2009-01-01",loo_PdfData,loo_SbResponseBody)
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_PdfData
    destroy loo_Crypt
    destroy loo_SbResponseBody
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    // Examine the request/response to see what happened.
    Write-Debug "response status code = " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "response status text = " + loo_Rest.ResponseStatusText
    Write-Debug "response header: " + loo_Rest.ResponseHeader
    Write-Debug "response body: " + loo_SbResponseBody.GetAsString()
    Write-Debug "---"
    Write-Debug "LastRequestStartLine: " + loo_Rest.LastRequestStartLine
    Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader
end if

// Examine the XML returned in the response body.
Write-Debug loo_SbResponseBody.GetAsString()
Write-Debug "----"
Write-Debug "Success."


destroy loo_Rest
destroy loo_PdfData
destroy loo_Crypt
destroy loo_SbResponseBody