amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
611 stars 733 forks source link

Please make a heading for C# programmers at "Generating a Java SDK with LWA token exchange and authentication" #862

Closed antonycartwright closed 1 year ago

antonycartwright commented 3 years ago

I've been using the C# SDK. The documentation lacks a lot of detail for us too. In my opinion, a new header for C# should be added here:

image

The documentation should probably give us at least basic steps for C# and then say "skip to Connecting to the Selling Partner API" when finished. In reality, there is a lot of missing detail for C#. In due time, this could be added to the documentation. I'd say there is around 3-4 pages of material to cover for C#.

bilal-yasin commented 3 years ago

@antonycartwright could you create a document somewhere if you have done all the steps successfully ? that could help others.

antonycartwright commented 3 years ago

@antonycartwright could you create a document somewhere if you have done all the steps successfully ? that could help others.

I finally became successful last week but haven't had time to review the project yet. I could make a guide if I had time. If I get time over the next few weeks, I'll do this. Antony...

bilal-yasin commented 3 years ago

@antonycartwright could you create a document somewhere if you have done all the steps successfully ? that could help others.

I finally became successful last week but haven't had time to review the project yet. I could make a guide if I had time. If I get time over the next few weeks, I'll do this. Antony...

I am stuck with an "Access to requested resource is denied", "Unauthorized" error. I am still trying to resolve this. A guide will be great or any hint on how to get this resolved.

antonycartwright commented 3 years ago

@antonycartwright could you create a document somewhere if you have done all the steps successfully ? that could help others.

I finally became successful last week but haven't had time to review the project yet. I could make a guide if I had time. If I get time over the next few weeks, I'll do this. Antony...

I am stuck with an "Access to requested resource is denied", "Unauthorized" error. I am still trying to resolve this. A guide will be great or any hint on how to get this resolved.

Hi, show your code. Antony...

bilal-yasin commented 3 years ago

I have tried "Website work flow" and "Self authorization" Code for Website Work Flow

                var token = //get the access_token form database and refresh it if expired;
                var client = new RestClient("https://sandbox.sellingpartnerapi-na.amazon.com");
                IRestRequest restRequest = new RestRequest("/orders/v0/orders", Method.GET);
                restRequest.AddQueryParameter("MarketplaceIds", "ATVPDKIKX0DER");
                restRequest.AddHeader("x-amz-access-token", token.AccessToken);
                var credentials = new SellerAPICredentials()
                {
                    AWSKey = "My aws key",
                    AWSSecret = "My aws secret",
                    RoleARN = "My role arn",
                    ClientId = "My client id",
                    ClientSecret = "My client secret",
                    RefreshToken = "My refresh token"
                };
                restRequest = AmazonService.SignWithSTSKeysAndSecurityToken(restRequest, client.BaseUrl.Host, credentials.RoleARN, credentials.AWSKey, credentials.AWSSecret);
                var response = client.Execute(restRequest);

For Self Authorization

                var baseUrl = "https://sellingpartnerapi-na.amazon.com";
                var client = new RestClient(baseUrl);
                IRestRequest restRequest = new RestRequest("/orders/v0/orders", Method.GET);
                restRequest.AddParameter("MarketplaceIds", "ATVPDKIKX0DER", ParameterType.QueryString);
                restRequest.AddParameter("CreatedAfter", DateTime.UtcNow.AddDays(-5).ToString("yyyy-MM-dd"), ParameterType.QueryString);
                var credentials = new SellerAPICredentials()
                {
                    AWSKey = "My aws key",
                    AWSSecret = "My aws secret",
                    RoleARN = "My role arn",
                    ClientId = "My clientId",
                    ClientSecret = "My client secret",
                    RefreshToken = "My refresh token"
                };
                restRequest = AmazonService.SignWithAccessToken(restRequest, credentials.ClientId, credentials.ClientSecret, credentials.RefreshToken);
                restRequest = AmazonService.SignWithSTSKeysAndSecurityToken(restRequest, client.BaseUrl.Host, credentials.RoleARN, credentials.AWSKey, credentials.AWSSecret);
                var response = client.Execute(restRequest);

Functions used here are from this issue https://github.com/amzn/selling-partner-api-models/issues/31

antonycartwright commented 3 years ago

I have tried "Website work flow" and "Self authorization" Code for Website Work Flow

                var token = //get the access_token form database and refresh it if expired;
                var client = new RestClient("https://sandbox.sellingpartnerapi-na.amazon.com");
                IRestRequest restRequest = new RestRequest("/orders/v0/orders", Method.GET);
                restRequest.AddQueryParameter("MarketplaceIds", "ATVPDKIKX0DER");
                restRequest.AddHeader("x-amz-access-token", token.AccessToken);
                var credentials = new SellerAPICredentials()
                {
                    AWSKey = "My aws key",
                    AWSSecret = "My aws secret",
                    RoleARN = "My role arn",
                    ClientId = "My client id",
                    ClientSecret = "My client secret",
                    RefreshToken = "My refresh token"
                };
                restRequest = AmazonService.SignWithSTSKeysAndSecurityToken(restRequest, client.BaseUrl.Host, credentials.RoleARN, credentials.AWSKey, credentials.AWSSecret);
                var response = client.Execute(restRequest);

For Self Authorization

                var baseUrl = "https://sellingpartnerapi-na.amazon.com";
                var client = new RestClient(baseUrl);
                IRestRequest restRequest = new RestRequest("/orders/v0/orders", Method.GET);
                restRequest.AddParameter("MarketplaceIds", "ATVPDKIKX0DER", ParameterType.QueryString);
                restRequest.AddParameter("CreatedAfter", DateTime.UtcNow.AddDays(-5).ToString("yyyy-MM-dd"), ParameterType.QueryString);
                var credentials = new SellerAPICredentials()
                {
                    AWSKey = "My aws key",
                    AWSSecret = "My aws secret",
                    RoleARN = "My role arn",
                    ClientId = "My clientId",
                    ClientSecret = "My client secret",
                    RefreshToken = "My refresh token"
                };
                restRequest = AmazonService.SignWithAccessToken(restRequest, credentials.ClientId, credentials.ClientSecret, credentials.RefreshToken);
                restRequest = AmazonService.SignWithSTSKeysAndSecurityToken(restRequest, client.BaseUrl.Host, credentials.RoleARN, credentials.AWSKey, credentials.AWSSecret);
                var response = client.Execute(restRequest);

Functions used here are from this issue amzn/selling-partner-api-models#31

Your code looks fine to me. Take a look at your region and check that. Also, check permissions/policies/roles. For me, I gave the user and the role full permissions in the console area.

coder771 commented 2 years ago

@antonycartwright can you please share your basic code for get orders using c# sdk.

ClementeGao commented 2 years ago

@antonycartwright @bilal-yasin can you share your email address? maybe we can discuss some questions together

rugved1991 commented 2 years ago

Hi @ClementeGao, @coder771,

Please let us know if you are still facing any issues. @antonycartwright @bilal-yasin thanks for the feedback regarding the C# SDK guide. We will surface this feedback to our tech writers. If you have created a guide already, please feel free to share with the developer community.

Best, Rugved Solutions Architect, SP API

github-actions[bot] commented 1 year ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

github-actions[bot] commented 1 year ago

closed for inactivity