I am posting data to the Amazon MerchantFullfillment uri using the WebRequest class (as detailed in https://msdn.microsoft.com/en-us/library/debx8sh9.aspx)
I get
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Either Action or Operation query parameter must be present.</Message>
</Error>
<RequestID>03f0e2ca-4c30-4012-9888-c33acc83446f</RequestID>
</ErrorResponse>
I am sending the Action query parameter "&Action=GetEligibleShippingServices" in the postData. Here is my code--I changed the endpoint url to try to see the request.
public void CreateAWSMessage(DateTime timestamp, ShipmentRequestDetails srd)
{
NameValueCollection awsField = new NameValueCollection();
string stringToSign = StringToSign(timestamp, srd, awsField);
string signature = CreateMessageSignature(srd, awsField, stringToSign);
string signedString = stringToSign + "&Signature=" + signature;
//string url = @"https://mws.amazonaws.com/MerchantFulfillment/2015-06-01";
string url = @"http://localhost/WebApplication1/Service.aspx";
WebRequest gess = WebRequest.Create(url);
HttpWebRequest httpGESS = (HttpWebRequest)gess;
string tmp = gess.Method;
httpGESS.Method = "POST";
httpGESS.ContentType = "x-www-form-urlencoded";
byte[] bytes = Encoding.UTF8.GetBytes(signedString);
httpGESS.ContentLength = bytes.Length;
using (Stream stream = httpGESS.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
string responseString;
using (StreamReader streamResponse = new StreamReader(httpGESS.GetResponse().GetResponseStream()))
{
responseString = streamResponse.ReadToEnd();
}
}
When I look at the request in debugging WebApplication1 (the endpoint), it shows the content as empty, and the method as "GET". That explains why the API is not receiving the Action query parameter. Why does the endpoint not see the request payload, or that it's a "POST"?
Here is the sanitized signedString:
AWSAccessKeyId=myAWSAccessKeyID&Action=GetEligibleShippingServices&MWSAuthToken=myMWSAuthToken&SellerId=mySellerID&ShipmentRequestDetails.AmazonOrderId=TST-1234567-1234568&ShipmentRequestDetails.ItemList.Item.1.OrderItemId=Item1&ShipmentRequestDetails.ItemList.Item.1.Quantity=2&ShipmentRequestDetails.MustArriveByDate=2016-12-31T01%3a15%3a52Z&ShipmentRequestDetails.PackageDimensions.Height=9&ShipmentRequestDetails.PackageDimensions.Length=7&ShipmentRequestDetails.PackageDimensions.Unit=inches&ShipmentRequestDetails.PackageDimensions.Width=8&ShipmentRequestDetails.SellerOrderId=TST-1234567-1234568&ShipmentRequestDetails.ShipDate=2016-12-27T01%3a15%3a52Z&ShipmentRequestDetails.ShipFromAddress.AddressLine1=799%20Central%20Ave&ShipmentRequestDetails.ShipFromAddress.AddressLine2=&ShipmentRequestDetails.ShipFromAddress.AddressLine3=&ShipmentRequestDetails.ShipFromAddress.City=Los%20Angeles&ShipmentRequestDetails.ShipFromAddress.CountryCode=US&ShipmentRequestDetails.ShipFromAddress.Email=jp%40example.com&ShipmentRequestDetails.ShipFromAddress.Name=JP%20test&ShipmentRequestDetails.ShipFromAddress.Phone=310-555-1212&ShipmentRequestDetails.ShipFromAddress.PostalCode=90021&ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode=CA&ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp=False&ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience=DeliveryConfirmationWithoutSignature&ShipmentRequestDetails.Weight.Unit=ounces&ShipmentRequestDetails.Weight.Value=120&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-12-26T21%3a53%3a05Z&Version=2015-06-01&Signature=d9rvl0XO7CbKuR+wNvCwh56ux5oNY/wv3I6z79+fG1M