Reputation: 1918
i'm trying to update stocks of my inventory Amazon Catalog using SP-API. This is my code:
private static IRestRequest CreateRequestFeedDocument()
{
IRestRequest restRequest = new RestRequest("feeds/2020-09-04/documents", Method.POST);
AmazonInventory obj = new AmazonInventory();
obj.SKU = "GD4297-44";
obj.Available = "true";
obj.Quantity = "20";
string xml = string.Empty;
using (var stringwriter = new System.IO.StringWriter())
{
var serializer = new XmlSerializer(obj.GetType());
serializer.Serialize(stringwriter, obj);
xml = stringwriter.ToString();
}
restRequest.AddParameter("contentType", xml, ParameterType.RequestBody);
restRequest.AddQueryParameter("MarketplaceIds", "APJ6JRA9NG5V4,A1PA6795UKMFR9,A13V1IB3VIYZZH,A1805IZSGTT6HS,A1F83G8C2ARO7P,A1RKKUPIHCS9HS,A2NODRKZP88ZB9");
AssumeRoleResponse assumeRoleResponse = null;
Task.Run(async () =>
{
assumeRoleResponse = await GetAssumeRoleTokenDetail();
}).GetAwaiter().GetResult();
// LWA credentials for app in amazon seller central
var clientId = AmazonCredentials.Default.ClientId;
var clientSecret = AmazonCredentials.Default.ClientSecret;
// generate refresh token with 'Authorize' action for app in amazon seller central
var refreshToken = AmazonCredentials.Default.RefreshToken;
var lwaAuthCreds = new LWAAuthorizationCredentials
{
ClientId = clientId,
ClientSecret = clientSecret,
RefreshToken = refreshToken,
Endpoint = new Uri("https://api.amazon.com/auth/o2/token")
};
restRequest = new LWAAuthorizationSigner(lwaAuthCreds).Sign(restRequest);
var awsAuthCreds = new AWSAuthenticationCredentials
{
AccessKeyId = assumeRoleResponse.Credentials.AccessKeyId,
SecretKey = assumeRoleResponse.Credentials.SecretAccessKey,
Region = AmazonCredentials.Default.Region
};
restRequest.AddHeader("x-amz-security-token", assumeRoleResponse.Credentials.SessionToken);
restRequest = new AWSSigV4Signer(awsAuthCreds)
.Sign(restRequest, restClient.BaseUrl.Host);
return restRequest;
}
restClient = new RestClient(live_url_base);
IRestRequest restRequest = CreateRequestFeedDocument();
var response = restClient.Execute(restRequest);
I get the following error
{
"errors": [
{
"code": "InvalidInput",
"message": "Invalid Input",
"details": ""
}
]
}
On the web I found this solution
adding this line:
restRequest.AddJsonBody(new { contentType = "text/xml; charset=UTF-8" });
I don't get Invalid inout error but I'm getting
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
[![enter image description here][1]][1]
Where I'm wrong?
Thanks [1]: https://i.sstatic.net/kw5JC.png
Upvotes: 1
Views: 5522
Reputation: 21
This is a new Announcement from Amazon.
works perfectly!
https://github.com/clousale/amazon-sp-api-php/issues/61#issuecomment-825542099
Upvotes: 1