user profile
Sign in
user profile

Configuring the C# SDK for the Selling Partner API

by Seller_zgzHOsax0TCcp

Hello all. I’m working with a C# SDK generated by Swagger for the new Selling-Partner API, and I’m having trouble setting up a Configuration object, which continually results in an “Unauthorized” error - no other details, just “Unauthorized”. Amazon gives good documentation for Java, but I have not found anything for C#, and the libraries for the two languages are significantly different - the C# library has no AWSAuthenticationCredentialsProvider type. Below is my current code:

			LWAAuthorizationCredentials authorizationCreds = new LWAAuthorizationCredentials
			{
				ClientId = "...",
				ClientSecret = "...",
				RefreshToken = "...",
				Endpoint = new Uri("https://api.amazon.com/auth/o2/token")
			};
			AWSAuthenticationCredentials authenticationCredentials = new AWSAuthenticationCredentials
			{
				AccessKeyId = "...",
				SecretKey = "...",
				Region = "us-east-1"
			};
			Configuration config = new Configuration();
			config.AuthenticationCredentials = authenticationCredentials;
			config.AuthorizationCredentials = authorizationCreds;

			ReportsApi reportsApi = new ReportsApi(config);
			var response = reportsApi.CreateReport(new CreateReportSpecification(null, "_GET_MERCHANT_LISTINGS_DATA_", DateTime.UtcNow, DateTime.UtcNow.AddDays(-3), new List<string>() { "ATVPDKIKX0DER" }));
			AuthorizationApi authApi = new AuthorizationApi(config);
			Console.WriteLine(response.Payload.ToString());

I have successfully used the LWAAuthorizationCredentials information in cURL, so I know it’s accurate and that we are successfully registered. The only other options seem to be that either my AWSAuthenticationCredentials are incorrect or that I’m missing something.

Below is the default constructor for Configuration, which is the one I am using. I have not been able to find any references to ApiKeys or ApiKeyPrefixes in the documentation.

    public Configuration()
    {
        UserAgent = "Swagger-Codegen/1.0.0/csharp";
        BasePath = "https://sellingpartnerapi-na.amazon.com";
        DefaultHeader = new ConcurrentDictionary<string, string>();
        ApiKey = new ConcurrentDictionary<string, string>();
        ApiKeyPrefix = new ConcurrentDictionary<string, string>();
    }

Has anyone else worked with the C# SDK yet? Any help would be much appreciated! Please let me know if more information is needed.

Tags: Reporting
00
347 views
43 replies
Reply
43 replies
Quick filters
Sort by
user profile
Seller_S31SMEGMdrcXt
In reply to: Seller_zgzHOsax0TCcp's post

Did you ever get this figured out? We are struggling as well. I have yet to be able to make the most basic api call with C#. The MWS sdk is fantastic. The SP-API is not well documented at all.

Reply
00
user profile
Seller_uQYpFKHAQOJUV
In reply to: Seller_zgzHOsax0TCcp's post

Hi, also interested in this. Bumping the question.
Also, did you guys try to use the “Login With Amazon API” to authenticate with SP-API?

Reply
00
user profile
Seller_Hfqi0sv3IpyHs
In reply to: Seller_zgzHOsax0TCcp's post

Hi, I’m trying to get this working as well and having trouble. Was just following the test code they have in the project. Has anyone gotten this to work?
Thanks,
Tom

Reply
00
user profile
Seller_esrWR4taZEdmh
In reply to: Seller_zgzHOsax0TCcp's post

The Refresh Token is a value that is issued one time only, which is used to get an Access Token once every hour. The Access Token is what is used to make api calls on a recurring basis.

The refresh token value comes from Seller Central when you self-authorize your app. Or it would come from amazon in the client authorization process.

As documented here:

Reply
00
user profile
Seller_esrWR4taZEdmh
In reply to: Seller_zgzHOsax0TCcp's post

Ok, great, so now we are both stuck at the same point?

The JsonParameters class is just the request body of the call. This varies depending on the api call.

Here is mine:

public class JsonParamaters
{
	public List<String> ShipmentStatusList = new List<string> { "WORKING" } ;	// 		optional 	A list of ShipmentStatus values. Used to select shipments with a current status that matches the status values that you specify. 	< enum (ShipmentStatusList) > array
										/* WORKING 	The shipment was created by the seller, but has not yet shipped.
											SHIPPED 	The shipment was picked up by the carrier.
											RECEIVING 	The shipment has arrived at the fulfillment center, but not all items have been marked as received.
											CANCELLED 	The shipment was cancelled by the seller after the shipment was sent to the fulfillment center.
											DELETED 	The shipment was cancelled by the seller before the shipment was sent to the fulfillment center.
											CLOSED 	The shipment has arrived at the fulfillment center and all items have been marked as received.
											ERROR 	There was an error with the shipment and it was not processed by Amazon.
											IN_TRANSIT 	The carrier has notified the fulfillment center that it is aware of the shipment.
											DELIVERED 	The shipment was delivered by the carrier to the fulfillment center.
											CHECKED_IN 	The shipment was checked-in at the receiving dock of the fulfillment center.
											*/

	public DateTime ShipmentIdList;		// optional 	A list of shipment IDs used to select the shipments that you want. If both ShipmentStatusList and ShipmentIdList are specified, only shipments that match both parameters are returned. 	< string > array
	public DateTime LastUpdatedAfter;	// optional 	A date used for selecting inbound shipments that were last updated after (or at) a specified time. The selection includes updates made by Amazon and by the seller. 	string (date-time)
	public DateTime LastUpdatedBefore;	// optional 	A date used for selecting inbound shipments that were last updated before (or at) a specified time. The selection includes updates made by Amazon and by the seller. 	string (date-time)

	public String QueryType = "SHIPMENT";	/* required 	Indicates whether shipments are returned using shipment information
								 (by providing the ShipmentStatusList or ShipmentIdList parameters),
								 using a date range (by providing the LastUpdatedAfter and LastUpdatedBefore parameters),
								 or by using NextToken to continue returning items specified in a previous request. 	enum (QueryType)
								 
								SHIPMENT 	Returns shipments based on the shipment information provided by the ShipmentStatusList or ShipmentIdList parameters.
								DATE_RANGE 	Returns shipments based on the date range information provided by the LastUpdatedAfter and LastUpdatedBefore parameters.
								NEXT_TOKEN
								*/
	public String NextToken;		// optional 	A string token returned in the response to your previous request. 	string
	public String MarketplaceId = "ATVPDKIKX0DER";
}
Reply
00
user profile
Seller_esrWR4taZEdmh
In reply to: Seller_zgzHOsax0TCcp's post

Did you try to make an API call? I think my problem is some credentials/configuration issue. I have been hoping that the next step, your API call would work, then that would confirm my suspicions.

Or are we both stuck at the same point?

The JsonParameters class is just the request body of the call.

Yeah, ok, not the best class name.

Reply
00
user profile
Seller_Hfqi0sv3IpyHs
In reply to: Seller_zgzHOsax0TCcp's post

Hi @NutritionGuy, Yes and getting " access to requested resource is denied". I have read somewhere and I’m trying to locate again, is there is something in the Documentation that is not clear or is missing saying there is a step that supposed to include the IAM Role info in some call or something like that. I have gone back over all the steps and I have everything setup according to the documentation. Not sure if maybe the account gets put in review after setting up? I’ll let you know if I find something or get it working.
Thanks,
Tom

Reply
00
user profile
Seller_esrWR4taZEdmh
In reply to: Seller_zgzHOsax0TCcp's post
This post has been deleted
Reply
00
user profile
Seller_Hfqi0sv3IpyHs
In reply to: Seller_zgzHOsax0TCcp's post

Hi @NutritionGuy, Yes I do the self authorization to get refresh token and use that. That part seems to work. So here is some links below that talk about my issue, which I think is the issue. Also, if you look at the java library. it has one more call for credentials which is “AWSAuthenticationCredentialsProvider”. There is no equivalent in C# library? And this is what that link below, all those people have this issue.

import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentials;

AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider=AWSAuthenticationCredentialsProvider.builder()
 .roleArn("myroleARN")
 .roleSessionName("myrolesessioname")
 .build();
Reply
00
user profile
Seller_esrWR4taZEdmh
In reply to: Seller_zgzHOsax0TCcp's post

I am using the project I found on GitHub which is basically a small C# library. It only does the authentication. It is called: “Amazon.SellingPartnerAPIAA”. I got to it through the docs.
I think this is only good for authentication, which isn’t working.

I am fine w/that, I can go through the docs and use RestSharp to build each call, but I just wish they would respond to my case which has been open for three weeks. For a company of their size, you would think they could find someone to do that.

I have tried access with two different apps using different roles, still not working.

It’s good to know others are having the same problem.

Reading through the thread now.

Reply
00
Go to original post

Similar Discussions