Tutorial: Submit a shipment invoice

Submit a shipment invoice for Fulfillment by Amazon (FBA) orders in the Brazil marketplace.

This tutorial describes how to submit a shipment invoice for FBA Onsite in the Brazil marketplace.

Prerequisites

To successfully complete this tutorial, you must have:

Step 1. Encode the XML file in Base64

Convert the XML file into Base64. You need the Base64 encoding for step 3.

Sample Java code

The following Java sample code takes a single input parameter xmlPath, which represents the file path, and returns the file's contents encoded in Base64 format.

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
import java.io.IOException;

public class XMLtoBase64 {
    public static String encodeXMLToBase64(String xmlPath) throws IOException {
        byte[] xmlBytes = Files.readAllBytes(Paths.get(xmlPath));
        return Base64.getEncoder().encodeToString(xmlBytes);
    }
}

Step 2. Calculate the invoice's MD5 digest

Calculate a Content-MD5 digest for the invoice XML file. You need this value for Step 3.

Sample Java code

The following Java sample code takes a single input parameter filePath, which represents the path to the file for which you must calculate the MD5 digest, and returns a string containing the Base64-encoded MD5 digest of the file's contents.

package com.util.hash;

import org.apache.commons.codec.binary.Base64;
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class HashGenerator {
    private static final Logger LOGGER = Logger.getLogger(HashGenerator.class.getName());

    public static String computeMD5HashFromFile(String filePath) {
        try (FileInputStream fis = new FileInputStream(filePath)) {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[8192];
            int bytesRead;
            while ((bytesRead = fis.read(buffer)) != -1) {
                md.update(buffer, 0, bytesRead);
            }
            return Base64.encodeBase64String(md.digest());
        } catch (IOException | NoSuchAlgorithmException e) {
            LOGGER.log(Level.SEVERE, "Error computing MD5 hash for file: " + filePath, e);
            throw new RuntimeException("Failed to compute MD5 hash", e);
        }
    }
}

Step 3. Submit the invoice

Submit the invoice by calling submitInvoice. Specify the Amazon Shipment ID in the shipmentId path parameter, the Base64-encoded invoice in the InvoiceContent body parameter, and the MD5 digest in the ContentMD5Value body parameter.

Step 4. Check the invoice submission status

Check the invoice status by calling getInvoiceStatus. Specify the Amazon Shipment ID to verify that the invoice submission was successful.


OSZAR »