Amazon MWS supports the management of seller orders for items sold on Amazon.com. Orders received can be downloaded and acknowledged using Amazon MWS. A variety of order report formats and actions are supported to meet specific seller needs.
For example, order reports can be set up for automatic generation following a schedule that's optimized to match seller workflow.
Report API lets you request various reports that help you manage your sales on Amazon.
What you should know about the Amazon MWS Reports API
Flowchart of the process for submitting and receiving an on-request report to Amazon,
First, we need to install
Amazon MWS c# client library
Once you download client library attach that project with your existing project and write the below code to call Report API.
Call to Request, download and convert the report into a C# class object.
Example to call report:
Note
We should create the report enumuration to use report type globally.
- public enum Report_Type
- {
- _GET_FLAT_FILE_OPEN_LISTINGS_DATA_,
- _GET_AMAZON_FULFILLED_SHIPMENTS_DATA_,
- _GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_,
- _GET_FLAT_FILE_ORDER_REPORT_DATA_,
- _GET_FLAT_FILE_ORDERS_DATA_,
- _GET_CONVERGED_FLAT_FILE_ORDER_REPORT_DATA_,
- _GET_FLAT_FILE_PAYMENT_SETTLEMENT_DATA_,
- _GET_PAYMENT_SETTLEMENT_DATA_,
- _GET_MERCHANT_LISTINGS_DATA_,
- _GET_MERCHANT_LISTINGS_DATA_LITE_,
- _GET_MERCHANT_LISTINGS_DATA_LITER_,
- _GET_MERCHANT_CANCELLED_LISTINGS_DATA_,
- _GET_AFN_INVENTORY_DATA_,
- _GET_MERCHANT_LISTINGS_INACTIVE_DATA_,
- _GET_MERCHANT_LISTINGS_DATA_BACK_COMPAT_
- }
Function to send Request. It will call Get_Report_List_Filtered_By (Report type,MarketplaceID)
- public List < Amazon_Open_Listings > RequestListingReport(Report_Type Report_Type, string "MarketPlaceId") {
- List < Amazon_Open_Listings > list = new List < Amazon_Open_Listings > ();
- try {
- var ReportId = Get_Report_List_Filtered_By(Report_Type, 1000, string "Seller ID");
- if (ReportId != null && ReportId.Count > 0) {
-
- var ReportPath = Download_Report(ReportId[0].ReportId, "Seller ID", "File path where you want to download report");
-
- list.AddRange(Convert_Open_Listings_As_List(ReportPath));
- }
- return list;
- } catch (Exception ex) {
- return null;
- }
- }
This function will accept Report type, Number of results of reports, and Seller ID. It returns Highest (latest) report id.
You can sort result by report id as well as request id, it depends on the situation.
- public List < ReportInfo > Get_Report_List_Filtered_By(Report_Type "Your report type", int _number_To_Return, string "Your Seller ID") {
- try {
- GetReportListRequest report_List_Request = new GetReportListRequest();
- report_List_Request.Merchant = "Your Seller ID";
- report_List_Request.MaxCount = _number_To_Return;
-
- TypeList tl = new TypeList();
- tl.Type.Add(Report_Type.ToString());
- report_List_Request.ReportTypeList = tl;
-
- GetReportListResponse report_List_Response = ReportClient.GetReportList(report_List_Request);
- GetReportListResult report_List_Result = report_List_Response.GetReportListResult;
-
- List < ReportInfo > retReport = report_List_Result.ReportInfo;
-
-
- retReport = retReport.OrderBy(x => x.ReportId).Reverse().ToList();
- return retReport;
- } catch (Exception ex) {
- return null;
- }
- }
Request parameters (All parameters are optional)
- ReportRequestIdList
A structured list of ReportRequestIdvalues. If you pass in ReportRequestIdvalues, other query conditions are ignored.
- ReportTypeList
A structured list of ReportType enumeration values.
- ReportProcessingStatusList
A structured list of report processing statuses by which to filter report requests.
- MaxCount
A non-negative integer that represents the maximum number of report requests to return. If you specify a number greater than 100, the request is rejected.
- RequestedFromDate
The start of the date range used for selecting the data to report, in ISO 8601 date time format.
- RequestedToDate
The end of the date range used for selecting the data to report, in ISO 8601 date time format.
This function accepts report id, seller id and File path where the report will be downloaded.
- public string Download_Report(string _report_ID, string "Seller ID", string BasePath )
- {
- GetReportRequest get_Report = new GetReportRequest();
- get_Report.Merchant = "Seller ID";
- string path = _report_ID + "_" + Guid.NewGuid();
- string thePath = BasePath + "\\" + String.Format("{0}.txt", path);
- get_Report.ReportId = _report_ID;
-
- get_Report.Report = File.Open(thePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- GetReportResponse report_Response = ReportClient.GetReport(get_Report);
- get_Report.Report.Close();
- return thePath;
- }
GetReport
It will returns the contents of a report and the Content-MD5 header for the returned report body.
Request parameters (Required)
ReportId
A unique identifier of the report to download, obtained from the GetReportList operation or the GeneratedReportId of a ReportRequest.
This will convert/map our tab-delimited report to C# class model so we can use it as a list of models.
- public List<Amazon_Open_Listings> Convert_Open_Listings_As_List(string reportPath)
- {
-
- List<Amazon_Open_Listings> openList = new List<Amazon_Open_Listings>();
-
-
- if (File.Exists(reportPath))
- {
-
- StreamReader reportReader;
- reportReader = File.OpenText(reportPath);
-
-
- string line;
- while ((line = reportReader.ReadLine()) != null)
- {
-
- string[] columns = line.Split('\t');
-
- Amazon_Open_Listings listing = new Amazon_Open_Listings();
- listing.SKU = columns[3].ToString();
- listing.FulFilledBy = "MFN";
- listing.Title = columns[0].ToString();
- listing.opendate = columns[6].ToString();
- listing.ASIN = columns[22].ToString();
- listing.Price = columns[4].ToString();
- listing.Qty = columns[5].ToString();
- listing.Recorded = System.DateTime.Now;
-
- openList.Add(listing);
-
- }
- reportReader.Close();
- }
- if (openList != null && openList.Count > 0)
- return openList.Skip(1).ToList();
- return openList;
- }
Note
Here, we should skip the first line because it contains Headers.
And here is our class/model,
- public partial class Amazon_Open_Listings
- {
- public string SKU { get; set; }
- public string ASIN { get; set; }
- public string ProfileName { get; set; }
- public int ProfileID { get; set; }
- public string FulFilledBy { get; set; }
- public string opendate { get; set; }
- public string productId { get; set; }
- public string Price { get; set; }
- public string Qty { get; set; }
- public string Report_ID { get; set; }
- public System.DateTime Recorded { get; set; }
- public Nullable<decimal> Lowest_Price { get; set; }
- public string Title { get; set; }
- public Nullable<decimal> AmazonSalesRank { get; set; }
- public string FileUrl { get; set; }
- public string Carrier { get; set; }
- public string Service { get; set; }
- public string TrackingNumber { get; set; }
- public decimal ShippingFee { get; set; }
- public string OrderId { get; set; }
-
- }