Amazon SP API for ET-Connector v1.3.77

Amazon selling partner API for ET-Connector

Installation

Installations requires minimal steps:

Installation on ET-Connector 11: Add library to classpath

grafik.png

Setup AMAZON SP API app client

Documentation of steps required to setup the app client.

Prerequistes to create the app client

1)  Register as developer by the following steps: https://developer-docs.amazon.com/sp-api/docs/register-as-a-private-developer

NOTE 1: Don't forget to apply ALL roles and also the roles for restricted data access, see screenshot below

NOTE 2: If you have an existing developer profile and the roles have been not enabled before, apply the newly approved role to your application. Save the changes and re-list the application. After the application is approved, get new authorizations to generate a new refresh token that will grant access to the API operations, reports, feeds and notifications the new role will provide.

grafik.png


2) Apply for PII role to get personal data (invoice address etc.) : https://developer-docs.amazon.com/sp-api/docs/applying-for-pii-roles

3) Create and configure AMAZON S3 access : https://developer-docs.amazon.com/sp-api/docs/creating-and-configuring-iam-policies-and-entities

Note the IAM ARN of the ROLE!

Create the app client

1) Goto Seller central

Unbenannt.png

2)  Add a new app client

grafik.png

3) Register the app by giving an arbitrary name

grafik.png

4) Goto Credentials for using SP API

Credentials for using SP API

For the access to SellerCentral you need to create a private app, refer to Setup AMAZON SP API app.

There 3 keys needed to access the AMAZON Selling partner API:

You can get this three keys here:

1) Goto seller cental -> Apps & Services -> Develop apps

Unbenannt.png

2) Get the client ID and client secret by viewing the LWA credentials

Unbenannt.png

Unbenannt.png

3) Get the Authorization-Token under "Authorize". Authorization Token starts with "Atzr..."

Unbenannt.png

Unbenannt.png

Using Orders v0 API

The orders API keeps tracks on new orders by caching the already processed orders and avoid unnecessary processing.

Notes:

API calls

getOrders()

SellingPartnerAPICallResult getOrders(
          SellingPartnerAPIClient c,
          SellingPartnerMarketPlace marketplace,
          boolean forcefetch,
          Logger log )

confirmShipment()

    String orderid = "902-1106328-1059050";
    String packagedetail ="<packageDetail>
    <packageReferenceId>1</packageReferenceId>
    <carrierCode>FedEx</carrierCode>
    <carrierName>FedEx</carrierName>
    <shippingMethod>FedEx Ground</shippingMethod>
    <trackingNumber>112345678</trackingNumber>
    <shipDate>2022-02-11T01:00:00.000Z</shipDate>
    <shipFromSupplySourceId>057d3fcc-b750-419f-bbcd-4d340c60c430</shipFromSupplySourceId>
    <orderItems>
        <orderItemId>79039765272157</orderItemId>
        <quantity>1</quantity>
         <transparencyCodes>09876543211234567890</transparencyCodes>
    </orderItems>
</packageDetail>";

    SellingPartnerAPICallResult r_confirm_shipment = SellingPartnerAPI_Order.confirmShipment(
            SellingPartnerAPIClient c,
            SellingPartnerMarketPlaces.DE,
            orderid,
            packagedetail,
            log);
   
 if (r_confirm_shipment.hasError()) {
      System.err.println("Error: " + r_confirm_shipment.getErrorMessage());
    } else {
      JSONObject jsonResponse = r_confirm_shipment.getJSONResponse();
      System.err.println(XML.toString(jsonResponse, 2));
    }

updateShipment()

    String orderid = "902-1845936-5435065";
    SellingPartnerAPICallResult r_update_shipment = SellingPartnerAPI_Order.updateShipmentStatus(
            SellingPartnerAPIClient c,
            SellingPartnerMarketPlaces.DE,
            orderid,
            SellingPartnerAPI_Order.ShipmentStatus.PickedUp,
            log);
    if (r_update_shipment.hasError()) {
      System.err.println("Error: " + r_update_shipment.getErrorMessage());
    } else {
      System.err.println(r_update_shipment.getJSONResponseAsXML());
    }

Usages

Add a new "Script" workflow item and paste the following content:

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Orders
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Logger;
import org.json.JSONObject;
import org.json.XML;
import com.sbs.data.*;

// NOTE!!!!
// If you want to force fetch of order,
// A) Use flag force below, see comments
// B) Delete file AMAZONSP_LAST_ORDER_DATE

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
Handler[] lha = log.getHandlers();
for (int h=0;h<lha.length;h++) {
  log.removeHandler(lha[h]);
}
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
      "Atzr|<yourauthorizationtoken>",
      "<yourclientid>",
      "<yourclientsecret>",
      log);
    
        SellingPartnerAPI_Order o = new SellingPartnerAPI_Order();
        SellingPartnerAPICallResult r = o.getOrders(
                spclient,
                SellingPartnerMarketPlaces.DE, // Default marketplace is DE, set other iso codes for other marketplaces
                false, // Set to true to force fetch from yesterday on
                log);
        DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
        if (r.hasError()) {
          dn_amazonsp.addChild("Error").setTextData("Error calling API: "+ r.getErrorMessage());
        } else {
          String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + XML.toString(r.getJSONResponse(), 2);
          DataNode dn_xml = DataUtils.parseXerces(xml.getBytes("utf-8"), null);
          dn_amazonsp.addChild(dn_xml);
        }
}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}    

Example response:

Unbenannt.png

Using Reports v2021-06-30 API

The reports API downloads flatfile or XML data from a date in the past to now depending on report type.

Notes:

Synchronous createReport / waitForReport

API calls
String SellingPartnerAPI_Reports.createReport(         
SellingPartnerAPIClient c,         
SellingPartnerMarketPlace marketplace,         
SellingPartnerAPI_Reports.ReportType feedtype,         
String reportoptions,         
long date_start,         
Logger log )

ProcessResult waitForReport(
SellingPartnerAPIClient spclient,
String reportid,
null,
Logger log)

Add a new "Script" workflow item and paste the following content:

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Reports
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONObject;
import org.json.XML;
import com.sbs.data.*;

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
      "Atzr|<yourauthorizationtoken>",
      "<yourclientid>",
      "<yourclientsecret>",
    log);
    
    // See list of available feedsreports here:
    // https://developer-docs.amazon.com/sp-api/docs/report-type-values
    
    /** 
    
    Report  types:
    GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING,
    GET_ORDER_REPORT_DATA_INVOICING,
    GET_ORDER_REPORT_DATA_TAX,
    GET_ORDER_REPORT_DATA_SHIPPING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_SHIPPING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_TAX,
    GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL,
    GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL,
    GET_FLAT_FILE_ARCHIVED_ORDERS_DATA_BY_ORDER_DATE,
    GET_XML_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL,
    GET_XML_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL,
    GET_FLAT_FILE_PENDING_ORDERS_DATA,
    GET_PENDING_ORDERS_DATA,
    GET_CONVERGED_FLAT_FILE_PENDING_ORDERS_DATA,
    GET_FLAT_FILE_OPEN_LISTINGS_DATA,
    GET_MERCHANT_LISTINGS_ALL_DATA,
    GET_MERCHANT_LISTINGS_DATA,
    GET_MERCHANT_LISTINGS_INACTIVE_DATA,
    GET_MERCHANT_LISTINGS_DATA_BACK_COMPAT,
    GET_MERCHANT_LISTINGS_DATA_LITE,
    GET_MERCHANT_LISTINGS_DATA_LITER,
    GET_MERCHANT_CANCELLED_LISTINGS_DATA,
    GET_MERCHANTS_LISTINGS_FYP_REPORT,
    GET_MFN_PANEU_OFFER_STATUS,
    GET_REFERRAL_FEE_PREVIEW_REPORT,
    GET_EASYSHIP_DOCUMENTS,
    GET_EASYSHIP_PICKEDUP,
    GET_EASYSHIP_WAITING_FOR_PICKUP,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_GENERAL,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_TAX,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_SALES_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_PROMOTION_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_TAXES_DATA,
    GET_REMOTE_FULFILLMENT_ELIGIBILITY,
    GET_AFN_INVENTORY_DATA,
    GET_AFN_INVENTORY_DATA_BY_COUNTRY,
    GET_LEDGER_SUMMARY_VIEW_DATA,
    GET_LEDGER_DETAIL_VIEW_DATA,
    GET_RESERVED_INVENTORY_DATA,
    GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA,
    GET_FBA_MYI_ALL_INVENTORY_DATA,
    GET_RESTOCK_INVENTORY_RECOMMENDATIONS_REPORT,
    GET_FBA_FULFILLMENT_INBOUND_NONCOMPLIANCE_DATA,
    GET_STRANDED_INVENTORY_UI_DATA,
    GET_STRANDED_INVENTORY_LOADER_DATA,
    GET_FBA_STORAGE_FEE_CHARGES_DATA,
    GET_PRODUCT_EXCHANGE_DATA,
    GET_FBA_INVENTORY_PLANNING_DATA,
    GET_FBA_OVERAGE_FEE_CHARGES_DATA,
    GET_FBA_ESTIMATED_FBA_FEES_TXT_DATA,
    GET_FBA_REIMBURSEMENTS_DATA,
    GET_FBA_FULFILLMENT_LONGTERM_STORAGE_FEE_CHARGES_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_REPLACEMENT_DATA,
    GET_FBA_RECOMMENDED_REMOVAL_DATA,
    GET_FBA_FULFILLMENT_REMOVAL_ORDER_DETAIL_DATA,
    GET_FBA_FULFILLMENT_REMOVAL_SHIPMENT_DETAIL_DATA,
    GET_FBA_UNO_INVENTORY_DATA,
    GET_FBA_SNS_FORECAST_DATA,
    GET_FBA_SNS_PERFORMANCE_DATA,
    GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE,
    GET_V2_SETTLEMENT_REPORT_DATA_XML,
    GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2,
    GET_SELLER_FEEDBACK_DATA,
    GET_V1_SELLER_PERFORMANCE_REPORT,
    GET_V2_SELLER_PERFORMANCE_REPORT,
    GET_PROMOTION_PERFORMANCE_REPORT,
    GET_COUPON_PERFORMANCE_REPORT,
    GST_MTR_STOCK_TRANSFER_REPORT,
    GST_MTR_B2B,
    GST_MTR_B2C,
    GET_FLAT_FILE_SALES_TAX_DATA,
    SC_VAT_TAX_REPORT,
    GET_VAT_TRANSACTION_DATA,
    GET_GST_MTR_B2B_CUSTOM,
    GET_GST_MTR_B2C_CUSTOM,
    GET_GST_STR_ADHOC,
    GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT,
    GET_XML_VAT_INVOICE_DATA_REPORT,
    GET_XML_BROWSE_TREE_DATA

*/
    
        DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
        String merchantidentifier = "123";
        String reportid = SellingPartnerAPI_Reports.createReport(
                spclient,
                SellingPartnerMarketPlaces.DE,
                SellingPartnerAPI_Reports.ReportType.GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING,
                null,
                System.currentTimeMillis() - DateTimeTools.ONEHOURMILLIS * 8, // 8 hours till now
                log);
        if (reportid != null) {
          dn_amazonsp.addChild("ReportID").setTextData(reportid);
          ProcessResult report_result = SellingPartnerAPI_Reports.waitForReport(spclient, reportid, null, log);
          if (report_result != null && report_result.isProcessed()) {
            String reportdata = report_result.getReport();
            if (reportdata.contains("<?xml")) {
               DataNode dn_xml = DataUtils.parseXerces(reportdata.getBytes("utf-8"), null);
               dn_amazonsp.addChild(dn_xml);
             }
             else {
               dn_amazonsp.addChild("DATA").setTextData(reportdata);
             }
          }
          else {
            dn_amazonsp.addChild("Report has been cancelled");
          }
        }
        else {
            throw new Exception("Unknown error");
        }
}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}    

Example response from the GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING:

Unbenannt.png

Already created reports by getReports()


Some reports like scheduled report ("Settlement reports") cannot be created, they are automatically created and must be searched and returned.

API calls


SellingPartnerAPICallResult response = SellingPartnerAPI_Reports.getReports(
          SellingPartnerAPIClientspclient,
          SellingPartnerMarketPlace marketplace, 
          SellingPartnerAPI_Reports.ReportType reporttype,
          System.currentTimeMillis() - DateTimeTools.ONEHOURMILLIS * 48,
          log);

ProcessResult SellingPartnerAPI_Reports.waitForReport(
SellingPartnerAPIClient spclient,
String reportid,
null,
Logger log)

Add a new "Script" workflow item and paste the following content:

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Reports
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.XML;
import com.sbs.data.*;

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
Handler[] lha = log.getHandlers();
for (int h=0;h<lha.length;h++) {
  log.removeHandler(lha[h]);
}
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
              "Atzr|<yourauthorizationtoken>",
              "<yourclientid>",
              "<yourclientsecret>",
              log);
    
    // See list of available feedsreports here:
    // https://developer-docs.amazon.com/sp-api/docs/report-type-values
    
    /** 
    
    Report  types:

    GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING,
    GET_ORDER_REPORT_DATA_INVOICING,
    GET_ORDER_REPORT_DATA_TAX,
    GET_ORDER_REPORT_DATA_SHIPPING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_SHIPPING,
    GET_FLAT_FILE_ORDER_REPORT_DATA_TAX,
    GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL,
    GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL,
    GET_FLAT_FILE_ARCHIVED_ORDERS_DATA_BY_ORDER_DATE,
    GET_XML_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL,
    GET_XML_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL,
    GET_FLAT_FILE_PENDING_ORDERS_DATA,
    GET_PENDING_ORDERS_DATA,
    GET_CONVERGED_FLAT_FILE_PENDING_ORDERS_DATA,
    GET_FLAT_FILE_OPEN_LISTINGS_DATA,
    GET_MERCHANT_LISTINGS_ALL_DATA,
    GET_MERCHANT_LISTINGS_DATA,
    GET_MERCHANT_LISTINGS_INACTIVE_DATA,
    GET_MERCHANT_LISTINGS_DATA_BACK_COMPAT,
    GET_MERCHANT_LISTINGS_DATA_LITE,
    GET_MERCHANT_LISTINGS_DATA_LITER,
    GET_MERCHANT_CANCELLED_LISTINGS_DATA,
    GET_MERCHANTS_LISTINGS_FYP_REPORT,
    GET_MFN_PANEU_OFFER_STATUS,
    GET_REFERRAL_FEE_PREVIEW_REPORT,
    GET_EASYSHIP_DOCUMENTS,
    GET_EASYSHIP_PICKEDUP,
    GET_EASYSHIP_WAITING_FOR_PICKUP,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_GENERAL,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING,
    GET_AMAZON_FULFILLED_SHIPMENTS_DATA_TAX,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_SALES_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_PROMOTION_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_TAXES_DATA,
    GET_REMOTE_FULFILLMENT_ELIGIBILITY,
    GET_AFN_INVENTORY_DATA,
    GET_AFN_INVENTORY_DATA_BY_COUNTRY,
    GET_LEDGER_SUMMARY_VIEW_DATA,
    GET_LEDGER_DETAIL_VIEW_DATA,
    GET_RESERVED_INVENTORY_DATA,
    GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA,
    GET_FBA_MYI_ALL_INVENTORY_DATA,
    GET_RESTOCK_INVENTORY_RECOMMENDATIONS_REPORT,
    GET_FBA_FULFILLMENT_INBOUND_NONCOMPLIANCE_DATA,
    GET_STRANDED_INVENTORY_UI_DATA,
    GET_STRANDED_INVENTORY_LOADER_DATA,
    GET_FBA_STORAGE_FEE_CHARGES_DATA,
    GET_PRODUCT_EXCHANGE_DATA,
    GET_FBA_INVENTORY_PLANNING_DATA,
    GET_FBA_OVERAGE_FEE_CHARGES_DATA,
    GET_FBA_ESTIMATED_FBA_FEES_TXT_DATA,
    GET_FBA_REIMBURSEMENTS_DATA,
    GET_FBA_FULFILLMENT_LONGTERM_STORAGE_FEE_CHARGES_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA,
    GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_REPLACEMENT_DATA,
    GET_FBA_RECOMMENDED_REMOVAL_DATA,
    GET_FBA_FULFILLMENT_REMOVAL_ORDER_DETAIL_DATA,
    GET_FBA_FULFILLMENT_REMOVAL_SHIPMENT_DETAIL_DATA,
    GET_FBA_UNO_INVENTORY_DATA,
    GET_FBA_SNS_FORECAST_DATA,
    GET_FBA_SNS_PERFORMANCE_DATA,
    GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE,
    GET_V2_SETTLEMENT_REPORT_DATA_XML,
    GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2,
    GET_SELLER_FEEDBACK_DATA,
    GET_V1_SELLER_PERFORMANCE_REPORT,
    GET_V2_SELLER_PERFORMANCE_REPORT,
    GET_PROMOTION_PERFORMANCE_REPORT,
    GET_COUPON_PERFORMANCE_REPORT,
    GST_MTR_STOCK_TRANSFER_REPORT,
    GST_MTR_B2B,
    GST_MTR_B2C,
    GET_FLAT_FILE_SALES_TAX_DATA,
    SC_VAT_TAX_REPORT,
    GET_VAT_TRANSACTION_DATA,
    GET_GST_MTR_B2B_CUSTOM,
    GET_GST_MTR_B2C_CUSTOM,
    GET_GST_STR_ADHOC,
    GET_FLAT_FILE_VAT_INVOICE_DATA_REPORT,
    GET_XML_VAT_INVOICE_DATA_REPORT,
    GET_XML_BROWSE_TREE_DATA
*/
    
    DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
    SellingPartnerAPICallResult response = SellingPartnerAPI_Reports.getReports(
          spclient,
          SellingPartnerMarketPlaces.DE,
          SellingPartnerAPI_Reports.ReportType.GET_V2_SETTLEMENT_REPORT_DATA_XML,
          System.currentTimeMillis() - DateTimeTools.ONEHOURMILLIS * 48,
          log);
    if (response.hasError()) {
      throw new TestException(response.getErrorMessage());
    } else {
      JSONArray ja = response.getJSONResponse().getJSONArray("reports");
      for (int i = 0; i < ja.length(); i++) {
        JSONObject report = ja.getJSONObject(i);
        String reportid = report.getString("reportId");
        DataNode dn_report = dn_amazonsp.addChild("Report");
        dn_report.addChild("ReportID").setTextData(reportid);
        dn_report.addChild("ReportTime").setTextData(report.getString("processingEndTime"));
        ProcessResult report_result = SellingPartnerAPI_Reports.waitForReport(spclient, reportid, null, log);
        if (report_result != null && report_result.isProcessed()) {
          String reportdata = report_result.getReport();
          if (reportdata.contains("<?xml")) {
             DataNode dn_xml = DataUtils.parseXerces(reportdata.getBytes("utf-8"), null);
             dn_report.addChild(dn_xml);
           }
           else {
             dn_report.addChild("DATA").setTextData(reportdata);
           }
        }
        else {
          dn_report.addChild("Report has been cancelled");
        }
      }
    }

}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}    

Using Feeds v2021-06-30 API

The feeds API uplods data for i.e. prices and products to AMAZON

API calls:

String uploadFeed(
          SellingPartnerAPIClient c,
          SellingPartnerMarketPlace marketplace,
          String mercantidentifier,
          FeedType feedtype,
          Map feedoptions,
          String feeddata,
          Logger log )


    ProcessResult uploadVATInvoice(
          SellingPartnerAPIClient c,
          SellingPartnerMarketPlace marketplace,
          String mercantidentifier,
          String invoicenumber,
          String orderid,
          String totalamount,
          String totalamountvat,
          Object feeddata,
          { boolean onlywaitforinqueue },
          Logger log )

Usage examples

POST_ORDER_ACKNOWLEDGEMENT_DATA

Add a template for generating upload(feed) data and add a "Script" workflow item.

grafik.png

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Feeds
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import org.json.JSONObject;
import org.json.XML;
import com.sbs.data.*;

// Get feed from DATA-OUT
String feeddata = null;
DataNode dn_in = DATA_OUT.getChild("OUT");
if (dn_in!=null) {
    feeddata = dn_in.getTextData();
}
if (feeddata == null) {
    throw new Exception("Can't find input for AMAZON SP Feed");
}

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
Handler[] lha = log.getHandlers();
for (int h=0;h<lha.length;h++) {
  log.removeHandler(lha[h]);
}
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
      "Atzr|<yourauthorizationtoken>",
      "<yourclientid>",
      "<yourclientsecret>",
    log);
    
    // See list of available feeds here:
    // https://developer-docs.amazon.com/sp-api/docs/feed-type-values
    
    /** 
    
    Feed types:
    JSON_LISTINGS_FEED,
    POST_PRODUCT_DATA,
    POST_INVENTORY_AVAILABILITY_DATA,
    POST_PRODUCT_OVERRIDES_DATA,
    POST_PRODUCT_PRICING_DATA,
    POST_PRODUCT_IMAGE_DATA,
    POST_PRODUCT_RELATIONSHIP_DATA,
    POST_FLAT_FILE_INVLOADER_DATA,
    POST_FLAT_FILE_LISTINGS_DATA,
    POST_FLAT_FILE_BOOKLOADER_DATA,
    POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA,
    POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA,
    POST_STD_ACES_DATA,
    POST_ORDER_ACKNOWLEDGEMENT_DATA,
    POST_PAYMENT_ADJUSTMENT_DATA,
    POST_ORDER_FULFILLMENT_DATA,
    POST_INVOICE_CONFIRMATION_DATA,
    POST_EXPECTED_SHIP_DATE_SOD,
    POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA,
    POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA,
    POST_FLAT_FILE_FULFILLMENT_DATA,
    POST_EXPECTED_SHIP_DATE_SOD_FLAT_FILE,
    POST_FULFILLMENT_ORDER_REQUEST_DATA,
    POST_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA,
    POST_FBA_INBOUND_CARTON_CONTENTS,
    POST_FLAT_FILE_FULFILLMENT_ORDER_REQUEST_DATA,
    POST_FLAT_FILE_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA,
    POST_FLAT_FILE_FBA_CREATE_INBOUND_PLAN,
    POST_FLAT_FILE_FBA_UPDATE_INBOUND_PLAN,
    POST_FLAT_FILE_FBA_CREATE_REMOVAL,
    RFQ_UPLOAD_FEED,
    POST_EASYSHIP_DOCUMENTS,
    UPLOAD_VAT_INVOICE
    */
    
        DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
        String merchantidentifier = "123";

        SellingPartnerAPI_Feeds.FeedType ft =  SellingPartnerAPI_Feeds.FeedType.POST_ORDER_ACKNOWLEDGEMENT_DATA
        boolean is_flat_file = ft.name().contains("FLAT_FILE");

        String feedid = SellingPartnerAPI_Feeds.uploadFeed(
                spclient,
                SellingPartnerMarketPlaces.DE,
                merchantidentifier,
                ft,
                null,
                feeddata,
                log);
        if (feedid != null) {
          dn_amazonsp.addChild("FeedID").setTextData(feedid);
          ProcessResult feed_result = SellingPartnerAPI_Feeds.waitForFeed(spclient, feedid, null, log);
          if (feed_result != null && feed_result.isProcessed()) {
            if (is_flat_file) {
                dn_amazonsp.addChild("Report").setTextData(feed_result.getReport());
            }
            else {
                try {
                    DataNode dn_xml = DataUtils.parseXerces(feed_result.getReport().getBytes("utf-8"), null);
                    dn_amazonsp.addChild(dn_xml);
                }
                catch (Exception ex) {
                    dn_amazonsp.addChild("Report").setTextData(feed_result.getReport());
                }
            }
          }
          else {
            throw new Exception("Feed process has been cancelled");
          }
        }
}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}    

UPLOAD_VAT_INVOICE

Upload invoice in 2 variants

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Feeds
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import org.json.JSONObject;
import org.json.XML;
import com.sbs.data.*;

// Get feed from DATA-OUT
String merchantidentifier = "123";
String invoicenumber = "RE4711"; // DATA_OUT.selectText("Invoice/Head/InvoiceNumber")[0];
String orderid = "XXX-XXXXXXX-XXXXXXX"; // DATA_OUT.selectText("Invoice/Head/BuyerPartyOrderNumber")[0];
String totalamount = "1,19"; // DATA_OUT.selectText("Invoice/Tail/TotalAmountGross")[0];
String totalamountvat = "0,19"; // DATA_OUT.selectText("Invoice/Tail/TotalAmountVAT")[0];

Object feeddata = null;
List lfeeddata = DATA_OUT.selectData("*/DATA");
if (lfeeddata!=null && !lfeeddata.isEmpty()) {
    feeddata = lfeeddata.get(0);
}
if (feeddata == null) {
    throw new Exception("Can't find input for AMAZON SP Feed");
}

DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
int size =0;
if (feeddata instanceof byte[]) {
    size = feeddata.length;
}
if (feeddata instanceof InputStream) {
    size = feeddata.available();
}
if (feeddata instanceof String) {
    size = feeddata.length();
}
dn_amazonsp.addChild("Size").setTextData(""+size);
if (size==0) {
    throw new Exception("Can't find input for AMAZON UPLOAD INVOICE feed");
}

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
Handler[] lha = log.getHandlers();
for (int h=0;h<lha.length;h++) {
  log.removeHandler(lha[h]);
}
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
      "Atzr|<yourauthorizationtoken>",
      "<yourclientid>",
      "<yourclientsecret>",
    log);
    

    // VARIANT 1: Wait for for feed result
    ProcessResult feed_result = SellingPartnerAPI_Feeds.uploadVATInvoice(
            spclient,
            SellingPartnerMarketPlaces.DE,
            merchantidentifier,
            invoicenumber,
            orderid,
            totalamountvat,
            totalamount,
             feeddata,
            log);
    if (feed_result != null && feed_result.isProcessed()) {
      dn_amazonsp.addChild("Report").setTextData(feed_result.getReport());
    } else {
      throw new Exception("Feed process has been cancelled");
    }

    // VARIANT 2: Don't wait for feed result
   ProcessResult feed_result = SellingPartnerAPI_Feeds.uploadVATInvoice(
            spclient,
            SellingPartnerMarketPlaces.DE,
            merchantidentifier,
            invoicenumber,
            orderid,
            totalamountvat,
            totalamount,
            feeddata,
            true,
            log);
   // No feed result available here, feed_result.isProcessed() == false
   // Save feedid for further purposes
   dn_amazonsp.addChild("FeedID").setTextData(feed_result.getProcessID());

}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}    

Get feed result for variant 2

// ------------------------
// (C) by devculture.eu 
// ------------------------
// Calling AMAZON SP API
// Get feed report
// ------------------------
import com.devc.amazon.aws.*;
import com.devc.amazon.sp.*;
import com.devc.commons.*;
import com.devc.logging.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import org.json.JSONObject;
import org.json.XML;
import com.sbs.data.*;

// Get feed from DATA-OUT
String feedid = DATA_OUT.selectText("FeedID")[0];

if (feedid == null) {
    throw new Exception("Can't find feed id for AMAZON SP Feed report");
}

DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
int size =0;
if (feeddata instanceof byte[]) {
    size = feeddata.length;
}
if (feeddata instanceof InputStream) {
    size = feeddata.available();
}
if (feeddata instanceof String) {
    size = feeddata.length();
}
dn_amazonsp.addChild("Size").setTextData(""+size);
if (size==0) {
    throw new Exception("Can't find input for AMAZON UPLOAD INVOICE feed");
}

// Bridge class to log to transaction log
class TransactionLogHandler extends java.util.logging.Handler {
  private static java.util.logging.Formatter _F = new java.util.logging.SimpleFormatter();
  public void publish( java.util.logging.LogRecord record ) {
    TRANSACTION.getTransactionLog().log(com.sbs.utils.logging.Level.INFO, _F.formatMessage(record));
  }
  public void flush() {
  }
  public void close() throws SecurityException {
  }
}

// Enable logging to ET-Connector
Logger log = Logging.getInstance().getLogger("AMAZONSP_"+TRANSACTIONID);
Handler[] lha = log.getHandlers();
for (int h=0;h<lha.length;h++) {
  log.removeHandler(lha[h]);
}
TransactionLogHandler tlh = new  TransactionLogHandler();
log.addHandler(tlh);
log.setLevel(Level.INFO); // Change log level here to get more details

try {
    // Set credentials
    // Parameter 1 AWS4EndPoint : For Germany  is AWS4EndPoints.EU_WEST_1 by default
    // Parameter 2 App authorisation : A string starting with "Atzr| ...."
    // Parameter 3 Client ID: A String starting with "amzn1.application-oa2-client ..."
    // Parameter 4 Client secret: A String starting with "amzn1.oa2-cs ..."
    SellingPartnerAPIClient spclient = new SellingPartnerAPIClient(
      AWS4EndPoints.EU_WEST_1,
      "Atzr|<yourauthorizationtoken>",
      "<yourclientid>",
      "<yourclientsecret>",
    log);
    
    DataNode dn_amazonsp = DATA_OUT.addChild("AMAZONSP");
    dn_amazonsp.addChild("FeedID").setTextData(feedid);
    ProcessResult feed_result = SellingPartnerAPI_Feeds.waitForFeed(spclient, feedid, null, log);
          if (feed_result != null && feed_result.isProcessed()) {
            if (is_flat_file) {
                dn_amazonsp.addChild("Report").setTextData(feed_result.getReport());
            }
            else {
                try {
                    DataNode dn_xml = DataUtils.parseXerces(feed_result.getReport().getBytes("utf-8"), null);
                    dn_amazonsp.addChild(dn_xml);
                }
                catch (Exception ex) {
                    dn_amazonsp.addChild("Report").setTextData(feed_result.getReport());
                }
            }
          }
          else {
            throw new Exception("Feed process has been cancelled");
          }
        }  

}
finally {
    if (tlh!=null) {
        log.removeHandler(tlh);
    }
}