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.