I'm trying to implement an in-house brewed php based way of uploading product to my Amazon marketplace using MWS.
I've trifled through the samples and thought I was on the right track given successful messages and FeedSubmissionID's but that is simply not the case and MWS tells you you've successfully completed a SubmitFeed even though you really didn't.
My question pertains to what exactly my $feed
variable should look like when I'm trying to update my inventory. Based off the Amazon MWS found here.
Code
This is a condensed version of SubmitFeedSample.php
.
My AWS_ACCESS_etc.. is inside my .config.inc.php which is included once at the very beginning. Almost certain all this is good though because I'm getting the success responses.
include_once ('.config.inc.php');
$serviceUrl = "https://mws.amazonservices.com";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
$config,
APPLICATION_NAME,
APPLICATION_VERSION);
$feed = '
<?xml version="1.0" ?>
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>A2EUQ1WTGCTBG2</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>424271</SKU>
<Quantity>8</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>
';
$marketplaceIdArray = array("Id" => array('ATVPDKIKX0DER'));
$feedHandle = @fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$parameters = array (
'Merchant' => MERCHANT_ID,
'MarketplaceIdList' => $marketplaceIdArray,
'FeedType' => '_POST_INVENTORY_AVAILABILITY_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false,
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
//'MWSAuthToken' => '<MWS Auth Token>', // Optional
);
rewind($feedHandle);
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
invokeSubmitFeed($service, $request);
@fclose($feedHandle);
function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
{
try {
$response = $service->submitFeed($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
echo(" SubmitFeedResponse\n");
if ($response->isSetSubmitFeedResult()) {
echo(" SubmitFeedResult\n");
$submitFeedResult = $response->getSubmitFeedResult();
if ($submitFeedResult->isSetFeedSubmissionInfo()) {
echo(" FeedSubmissionInfo\n");
$feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
if ($feedSubmissionInfo->isSetFeedSubmissionId())
{
echo(" FeedSubmissionId\n");
echo(" " . $feedSubmissionInfo->getFeedSubmissionId() . "\n");
}
if ($feedSubmissionInfo->isSetFeedType())
{
echo(" FeedType\n");
echo(" " . $feedSubmissionInfo->getFeedType() . "\n");
}
if ($feedSubmissionInfo->isSetSubmittedDate())
{
echo(" SubmittedDate\n");
echo(" " . $feedSubmissionInfo->getSubmittedDate()->format(DATE_FORMAT) . "\n");
}
if ($feedSubmissionInfo->isSetFeedProcessingStatus())
{
echo(" FeedProcessingStatus\n");
echo(" " . $feedSubmissionInfo->getFeedProcessingStatus() . "\n");
}
if ($feedSubmissionInfo->isSetStartedProcessingDate())
{
echo(" StartedProcessingDate\n");
echo(" " . $feedSubmissionInfo->getStartedProcessingDate()->format(DATE_FORMAT) . "\n");
}
if ($feedSubmissionInfo->isSetCompletedProcessingDate())
{
echo(" CompletedProcessingDate\n");
echo(" " . $feedSubmissionInfo->getCompletedProcessingDate()->format(DATE_FORMAT) . "\n");
}
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
So my $feed variable is the one I have in question. I do have the amzn-envelope.xsd and other .xsd files in the directory with it. What am I doing wrong?
EDIT
I found the solution was in fact my $feed
variable in that I did not need the \<\?xml version="1.0" \?> line which was part of my feed.