Hire the author: Lakshay G
This project is available at https://github.com/learningdollars/lakshay-mws-api
What is Amazon MWS?
Amazon Marketplace Web Service (Amazon MWS) is an integrated web service API that helps Amazon sellers to programmatically exchange data on listings, orders, payments, reports, and more. Data integration with Amazon enables high levels of selling automation, which can help sellers grow their business. By using Amazon MWS, sellers can increase selling efficiency, reduce labor requirements, and improve response time to customers.
In this blog, we will stick only with the reports part.
Motivation
It is expected that after this present situation of COVID-19 is over, the e-commerce industry will get a huge boost for which the sellers should be prepared beforehand which is the main thing that motivates me to do this project.
Goal
Not every seller can read the data in a JSON format or XML format, so my goal is to make these reports available in a tabular form and downloadable as a .csv which is readable by everyone easily.
Glossary
Settlement report: This report is useful for reconciling transactions with bank statements and reports
Project Requirements
- Basic programming fundamentals are a must
- Must have a little bit idea about Node.js and JavaScript
Note:
You can obtain the AWS KEY hereYou can obtain the AWS SECRET KEY here
Getting Started
1. Understanding the documentation, how each report will be fetched ?
Refer to this to understand which report requires which API operation to be performed and what are there enumeration values, because these two things will help us generate the reports easily. For example: One of the inventory reports is ‘All Listings Report’, that has the enumeration value of ‘_GET_MERCHANT_LISTINGS_ALL_DATA_’ and the API operation associated with this is RequestReport. So we will be requesting this report, which will in turn give us the request report ID. After this we will perform the getReportRequestList operation to get the generated Reports ID and finally we will perform getReport operation to get our requested report. This flow can also be understood by the picture shown below:
2. After understanding the documentation, let’s move on to the implementation part
We will be using amazon-mws npm package for the implementation purpose
- Install the package using npm install amazon-mws command and require it inside the Reports.js file, so that you can use the functions provided by the npm package
- We will be fetching 5 most important reports Inventory, Order, Settlement, Performance and Amazon Pay report
- For this we will need to define all the API operations associated with these reports respectively
- Inventory Report: requestReport -> getReportRequestList -> getReport
- Order Report: requestReport -> getReportRequestList -> getReport
- Performance Report: requestReport -> getReportRequestList -> getReport
- Amazon Pay Report: requestReport -> getReportRequestList -> getReport
- Settlement Report: getReportList -> getReport
NOTICE: We can’t request settlement reports as these are scheduled by Amazon itself.Therefore, we will be fetching only the latest one in this mws project
Here is the Report.js file
3. After this we will create another file named HelperReport.js, that will include the enumeration values of the reports to be generated and the array of requestID’s of different report
requestId’s are needed in order to keep a track of all the requested reports
4. Now let’s set up our app.js file which is going to perform the main magic
In this we will be exporting a class, whose constructor will set up some required values as entered by the user in the frontend(discussed later) and call the generateReports function which will step by step perform all the API operations required by respective reports
Also we will be exporting the reports generated/fetched in this file
5. Now comes the last step of our backend, to set up our server.js file
This file includes how the different requests are going to get served or how they are going to get redirected
Frontend
Lets design our home.ejs, loading.ejs and reportsPage.ejs files respectively
home.ejs
This will be our landing page, and includes one jumbotron (a big box for calling extra attention to some special content or information) and one form
loading.ejs
This page includes a progress bar that will complete once the reports are fetched properly
I took help of this video in order to implement a progress bar
reportsPage.ejs
This page includes how to display our reports that we fetched in our backend using mws API
This page also includes a feature of downloading a report as CSV which I implemented with the help of this solution.
Learning Tools
First of all, documentation is a must. Go through the amazon-mws documentation thoroughly, After that you can go through the following links (these helped me complete my project)
Link to design a progress bar
Link to create Download as CSV function for mws reports
Don’t write a messy code, everything should be well understood. As a result it will help you in debugging. Also, do a console.log() at each major step you feel is important or you feel maybe will throw some kind of error.
Learning Strategy
The major obstacle that I came across in order to implement this successfully was when I tried fetching settlement reports. I followed the traditional approach of performing requestReport API operation. So, in order to avoid these silly mistakes focus on the official documentation is a must. Don’t write a messy code, everything should be well understood. As a result it will help you in debugging. Also, do a console.log() at each major step you feel is important or you feel maybe will throw some kind of error.
Search terms
Amazon mws, Amazon mws node.js, Javascript mws reports generation
This project isn’t for the faint of heart
Try to be in a quiet place while doing this project, it requires focus.
Reflective Analysis
It was a fun learning experience to understand how to use Amazon MWS API. I didn’t know about this API earlier.A very common mistake that you are expected to make is with the API operation you will use for fetching settlement reports (Remember its getReportList and not requestReport)
Conclusion
This project includes the reports that are fetched using the MWS API, how about a complete project that includes some calculations from the reports data that is fetched and present it in graphical form to the seller and also guide him/her to follow certain steps to reduce losses
This project is available at https://github.com/learningdollars/lakshay-mws-api

