0
votes

I'm an Amazon FBA seller and I would like to begin to upload data regarding my sales in a more automated process using Amazon MWS. I just made an amazon MWS account and received my different IDs (Access Key Id, secret Access Key, ...).

I have the impression that most MWS developers use C#. I have a lot of Excel VBA experience but not in C#. Therefore, I'm not sure of the steps I have to follow.

On the webpage below, you can find a C# code that I would like to run:

http://www.samswiches.com/2011/02/how-to-use-amazon-mws-to-download-unshipped-order-reports/

Could you confirm the steps below are correct? :

1) Download Visual Studio => Do I need to download any extra package from Amazon?

2) In Visual Studio: File => New Project => C# console application

3) Erase all code and replace it by a copy-paste of the code found on above website => Do I need to put the code Inside something like "Sub - end Sub" in VBA?

4) Change "YourSecretKey", "YourSecretAccessKey", "YourSecretAccessKey", "YourMerchantID", "YourMarketplaceID" by my IDs.

5) Hit the run button

If it works, what will be the output like: An array inside Visual studio? A text file? A csv file? Where will it be stored?

I realize this is a very newbie question. However, I think that once I have a first code running correctly, my VBA experience will allow me to start efficiently from there.

Thanks in advance,

Diego.

2

2 Answers

3
votes

After looking the code from http://www.samswiches.com/2011/02/how-to-use-amazon-mws-to-download-unshipped-order-reports/ I tried and changed something, and it works. Here is my solution:

Here is the code.

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using MarketplaceWebService;
using MarketplaceWebService.Mock;
using MarketplaceWebService.Model;
using System.IO;
using System.Threading;


public void testReport()
{
String accessKeyId = "Your Access Key ID";
String secretAccessKey = "Your Secret Access Key";
const string merchantId = "Merchant ID";
const string marketplaceId = "Marketplace ID";

MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
config.ServiceURL = "https://mws.amazonservices.com";
const string applicationName = "ApplicationName";
const string applicationVersion = "0.01";

MarketplaceWebServiceClient service =
        new MarketplaceWebServiceClient(
               accessKeyId,
               secretAccessKey,
               applicationName,
               applicationVersion,
               config);



RequestReportRequest reportRequestRequest = new RequestReportRequest();
reportRequestRequest.Merchant = merchantId;

// you can change ReportType here:
//http://docs.developer.amazonservices.com/en_IN/reports/Reports_ReportType.html
reportRequestRequest.ReportType = “_GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_";




 RequestReportResponse requestResponse = service.RequestReport(reportRequestRequest);
 IdList lstRequestID = new IdList();

 lstRequestID.Id.Add
      (requestResponse.RequestReportResult.ReportRequestInfo.ReportRequestId);

  GetReportRequestListRequest reportRequestListRequest = new 
  GetReportRequestListRequest();
        reportRequestListRequest.Merchant = merchantId;
        reportRequestListRequest.ReportRequestIdList = lstRequestID;

        List<ReportRequestInfo> myListzz = new List<ReportRequestInfo>();

        GetReportRequestListResponse reportRequestListResponse = new 
GetReportRequestListResponse();
        reportRequestListResponse = 
service.GetReportRequestList(reportRequestListRequest);
        GetReportRequestListResult reportRequestListResult = new 
GetReportRequestListResult();
        reportRequestListResult = 
reportRequestListResponse.GetReportRequestListResult;
        myListzz = reportRequestListResult.ReportRequestInfo;

        if (myListzz.Count > 0)
        {
            while (myListzz[0].ReportProcessingStatus.ToString() != "_DONE_")
            {
                Console.WriteLine("Waiting for Report");
                Thread.Sleep(61000);
                reportRequestListResponse = 
                service.GetReportRequestList(reportRequestListRequest);
                reportRequestListResult = 
                reportRequestListResponse.GetReportRequestListResult;
                myListzz = reportRequestListResult.ReportRequestInfo;
            }


            if (myListzz[0].GeneratedReportId !=null)
            { 
                GetReportRequest reportRequest = new GetReportRequest();
                reportRequest.Merchant = merchantId;

                String source = "C:\\myreport.txt";
                reportRequest.ReportId = myListzz[0].GeneratedReportId;
                reportRequest.Report = File.Open(source, FileMode.Create, 
                FileAccess.ReadWrite);
                service.GetReport(reportRequest);
            }
        }
  }
1
votes

You are missing step 1b) Download the C# MWS Reports API Client Library. You may need other libraries to access other parts of the MWS API, but from a quick glance at that code above library is the main one.

Note that it refers to a lblStatus, which seems to be a label on a form, but nowhere in that post does it say anything else about that form. So step 2) probably is not a "console" style application, but a form based one, which also means, you shouldn't erase all code in step 3, but paste the code into whatever is the equivalent of a main() function (I've only ever used C and C++, but not C#, so I have no clue)