Skip to content

Kinggrass/Amazon-SP-API-CSharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon Selling Partner API C# Build status NuGet

This is an API Binding in .Net C# for the new Amazon Selling Partner API.

This library is based on the output of swagger-codegen with the OpenAPI files provided by Amazon and has been modified by the contributors.

The purpose of this package is to have an easy way of getting started with the Amazon Selling Partner API.


Requirements


Tasks


Installation NuGet

Install-Package CSharpAmazonSpAPI

Keys

Name Description
AccessKey AWS USER ACCESS KEY
SecretKey AWS USER SECRET KEY
RoleArn AWS IAM Role ARN (needs permission to “Assume Role” STS)
Region Marketplace region
ClientId Your amazon app id
ClientSecret Your amazon app secret

For more information about keys please check Amazon Selling Partner Api developer guide.


Usage

Configration

    AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential()
    {
         AccessKey = "AKIAXXXXXXXXXXXXXXX",
         SecretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
         RoleArn = "arn:aws:iam::XXXXXXXXXXXXX:role/XXXXXXXXXXXX",
         ClientId = "amzn1.application-XXX-client.XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
         ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
          RefreshToken= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
     });

Order Lsit ,For more orders sample please check Here.

   var orders= amazonConnection.Orders.ListOrders();
            

Order Lsit with parameter

            ParameterOrderList serachOrderList = new ParameterOrderList();
            serachOrderList.CreatedAfter = DateTime.UtcNow.AddHours(-24);
            serachOrderList.OrderStatuses = new List<OrderStatuses>();
            serachOrderList.OrderStatuses.Add(OrderStatuses.Unshipped);
            serachOrderList.MarketplaceIds = new List<string> { MarketPlace.UnitedArabEmirates.ID };

            var orders = amazonConnection.Orders.GetOrders(serachOrderList);
            

Report Lsit ,For more report sample please check Here.

            var parameters = new ParameterReportList();
            parameters.pageSize = 100;
            parameters.reportTypes = new List<ReportTypes>();
            parameters.reportTypes.Add(ReportTypes.GET_AFN_INVENTORY_DATA);
            parameters.marketplaceIds = new List<string>();
            parameters.marketplaceIds.Add(MarketPlace.UnitedArabEmirates.ID);
            var reports=amazonConnection.Reports.GetReports(parameters);

Custom Report

            var parameters = new ParameterCreateReportSpecification();
            parameters.reportType = ReportTypes.GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL;
            parameters.dataStartTime = DateTime.UtcNow.AddDays(-30);
            parameters.dataEndTime = DateTime.UtcNow.AddDays(-10);
            parameters.marketplaceIds = new MarketplaceIds();
            parameters.marketplaceIds.Add(MarketPlace.UnitedArabEmirates.ID);
            parameters.reportOptions = new AmazonSpApiSDK.Models.Reports.ReportOptions();

            var report= amazonConnection.Reports.CreateReport(parameters);

Product Pricing ,For more Pricing sample please check Here.

var data = amazonConnection.ProductPricing.GetPricing(new Parameter.ProductPricing.ParameterGetPricing()
            {
                MarketplaceId = MarketPlace.UnitedArabEmirates.ID,
                Asins = new string[] { "B00CZC5F0G" }
            });

Product Competitive Price

var data = amazonConnection.ProductPricing.GetCompetitivePricing(new Parameter.ProductPricing.ParameterGetCompetitivePricing()
            {
                MarketplaceId = MarketPlace.UnitedArabEmirates.ID,
                Asins = new string[] { "B00CZC5F0G" },

            });

Notifications Create Destination,For more Notifications sample please check Here.

//EventBridge
            var data = amazonConnection.Notification.CreateDestination(new AmazonSpApiSDK.Models.Notifications.CreateDestinationRequest()
            {
                Name = "CompanyName",
                ResourceSpecification = new AmazonSpApiSDK.Models.Notifications.DestinationResourceSpecification()
                {
                    EventBridge = new AmazonSpApiSDK.Models.Notifications.EventBridgeResourceSpecification("us-east-2", "999999999")
                }
            });

            //SQS
            var dataSqs = amazonConnection.Notification.CreateDestination(new AmazonSpApiSDK.Models.Notifications.CreateDestinationRequest()
            {
                Name = "CompanyName_AE",
                ResourceSpecification = new AmazonSpApiSDK.Models.Notifications.DestinationResourceSpecification
                {
                    Sqs = new AmazonSpApiSDK.Models.Notifications.SqsResource("arn:aws:sqs:us-east-2:9999999999999:NAME")
                }
            });

Notifications read messages

            var SQL_URL = "https://sqs.us-east-2.amazonaws.com/9999999999999/IUSER_SQS";
            ParameterMessageReceiver param = new ParameterMessageReceiver(Environment.GetEnvironmentVariable("AccessKey"), Environment.GetEnvironmentVariable("SecretKey"), SQL_URL, Amazon.RegionEndpoint.USEast2);

            CustomMessageReceiver messageReceiver = new CustomMessageReceiver();


            amazonConnection.Notification.StartReceivingNotificationMessages(param, messageReceiver);


        public class CustomMessageReceiver : IMessageReceiver
        {

            public void ErrorCatch(Exception ex)
            {
                //Your code here
            }

            public void NewMessageRevicedTriger(NotificationMessageResponce message)
            {
                //Your Code here
            }
        }

Feed Submit

Here Full sample for submit feed to change price and generate XML and get final report for result same as in doc. Notes: not all feed type finished as its big work and effort but all classes are partial for easy change and you can generate xml outside and use our library for get data , now we support only sumit existed product , change quantity and change price

            ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02");

            var list = new List<PriceMessage>();
            list.Add(new PriceMessage()
            {
                SKU = "8201031206122...",
                StandardPrice = new StandardPrice()
                {
                    currency = BaseCurrencyCode.AED.ToString(),
                    Value = (201.0522M).ToString("0.00")
                }
            });
            createDocument.AddPriceMessage(list);

            var xml = createDocument.GetXML();

            var feedID = amazonConnection.Feed.SubmitFeed(xml, FeedType.POST_PRODUCT_PRICING_DATA);

            Thread.Sleep(1000*30);

            var feedOutput=amazonConnection.Feed.GetFeed(feedID);

            var outPut=amazonConnection.Feed.GetFeedDocument(feedOutput.ResultFeedDocumentId);

            var reportOutpit = outPut.Url;

Q & A

If you have questions, please ask in GitHub discussions

discussions


ToDo

  • Improve documentation

Notes

If you are looking for a complete Feedback solution, you might want to consider giving Soon.se a shot.


Support & Consultation

We offer consultation on everything SP-API related. Book your meeting here:

Book Meeting


Thanks

Thanks go out to everybody who worked on this package.

About

Amazon Selling Partner API C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%