Android™
Android™
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 Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRest rest = new CkRest();
// 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
boolean bTls = true;
int port = 443;
boolean bAutoReconnect = true;
success = rest.Connect("mws.amazonservices.com",port,bTls,bAutoReconnect);
rest.put_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.
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.
CkBinData pdfData = new CkBinData();
success = pdfData.LoadFile("qa_data/pdf/sample.pdf");
// Get the MD5 hash of the PDF data.
CkCrypt2 crypt = new CkCrypt2();
crypt.put_HashAlgorithm("md5");
crypt.put_EncodingMode("base64");
String md5Hash = crypt.hashBdENC(pdfData);
rest.AddQueryParam("AWSAccessKeyId","0PB842ExampleN4ZTR2");
rest.AddQueryParam("Action","SubmitFeed");
rest.AddQueryParam("FeedType","_UPLOAD_VAT_INVOICE_");
rest.AddQueryParam("MWSAuthToken","EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE");
rest.AddQueryParam("MarketplaceIdList.Id.1","ATVExampleDER");
rest.AddQueryParam("SellerId","A1XExample5E6");
rest.AddQueryParam("ContentMD5Value",md5Hash);
rest.AddQueryParam("SignatureMethod","HmacSHA256");
rest.AddQueryParam("SignatureVersion","2");
rest.AddQueryParam("Version","2009-01-01");
// Add the MWS Signature param. (Also adds the Timestamp parameter using the curent system date/time.)
rest.AddMwsSignature("POST","/Feeds/2009-01-01","mws.amazonservices.com","YOUR_MWS_SECRET_ACCESS_KEY_ID");
rest.AddHeader("Content-Type","application/octet-stream");
CkStringBuilder sbResponseBody = new CkStringBuilder();
success = rest.FullRequestBd("POST","/Feeds/2009-01-01",pdfData,sbResponseBody);
if (rest.get_LastMethodSuccess() != true) {
Log.i(TAG, rest.lastErrorText());
return;
}
if (rest.get_ResponseStatusCode() != 200) {
// Examine the request/response to see what happened.
Log.i(TAG, "response status code = " + String.valueOf(rest.get_ResponseStatusCode()));
Log.i(TAG, "response status text = " + rest.responseStatusText());
Log.i(TAG, "response header: " + rest.responseHeader());
Log.i(TAG, "response body: " + sbResponseBody.getAsString());
Log.i(TAG, "---");
Log.i(TAG, "LastRequestStartLine: " + rest.lastRequestStartLine());
Log.i(TAG, "LastRequestHeader: " + rest.lastRequestHeader());
}
// Examine the XML returned in the response body.
Log.i(TAG, sbResponseBody.getAsString());
Log.i(TAG, "----");
Log.i(TAG, "Success.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}