Amazon MWS SubmitFeed error: Keys may not contain <

1.8k views Asked by At

I'm having problems submitting a feed to Amazon MWS. I keep receiving the following error: "Invalid query string provided - Keys may not contain <"

This is my code:

$apicall = $this->build_url($function, $params);
$ch = curl_init($apicall);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
if ($this->xml) {
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, (string)$this->xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: text/xml"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-MD5: " . base64_encode(md5($this->xml))));
}
else {
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$info = print_r(curl_getinfo($ch), true);
curl_close($ch);

$apicall is formed on-the-fly and comes in the form:

https://mws.amazonservices.com/Feeds/2009-01-01?ASINList.ASIN.1=B00C5XBAOA&AWSAccessKeyId=***&Action=SubmitFeed&FeedType=_POST_PRODUCT_PRICING_DATA_&MWSAuthToken=***&SellerId=***&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2015-06-09T09%3A58%3A01.000Z&Version=2009-01-01&Signature=***

(which works fine with other calls to Reports or to Orders)

$this->xml is kept as a "TEXT" field in the MySQL db; this is a sample XML (I added lines to make it readable):

<?xml version="1.0"?>
<AmazonEnvelope xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.01</DocumentVersion>
        <MerchantIdentifier>***</MerchantIdentifier>
    </Header>
    <MessageType>Price</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Price>
            <SKU>***</SKU>
            <StandardPrice currency="USD">33.5</StandardPrice>
        </Price>
    </Message>
</AmazonEnvelope>

I seem to review every single relevant link on the internet and cannot find the answer.

Maybe someone can give me a hint what may go wrong in the above code?

Thanks.

1

There are 1 answers

0
eez On

Found the solutions myself (after digging more that a day):

1) Content-MD5 must be calculated in the following way:

base64_encode(md5($this->xml, **true**));

(thanks to this answer: https://sellercentral.amazon.com/forums/message.jspa?messageID=2767745)

2) passing header parameters to cUrl must be one-time operation, that is - all headers have to be passed as an array.