<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>MYMERCHANT123</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>172210019669</DocumentTransactionID>
<StatusCode>Complete</StatusCode>
<ProcessingSummary>
<MessagesProcessed>0</MessagesProcessed>
<MessagesSuccessful>0</MessagesSuccessful>
<MessagesWithError>1</MessagesWithError>
<MessagesWithWarning>0</MessagesWithWarning>
</ProcessingSummary>
<Result>
<MessageID>0</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>5001</ResultMessageCode>
<ResultDescription>XML Parsing Fatal Error at Line 1, Column 1: Content is not allowed in prolog. Content is not allowed in prolog.</ResultDescription>
</Result>
</ProcessingReport>
</Message>
</AmazonEnvelope>
That is my error, and this is my code:
$requestXml = '<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>MYMERCHANT123</MerchantIdentifier>
</Header>
<MessageType>Product</MessageType>
<PurgeAndReplace>false</PurgeAndReplace>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Product>
<SKU>56789</SKU>
<StandardProductID>
<Type>ASIN</Type>
<Value>B0EXAMPLEG</Value>
</StandardProductID>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<DescriptionData>
<Title>Example Product Title</Title>
<Brand>Example Product Brand</Brand>
<Description>This is an example product description.</Description>
<BulletPoint>Example Bullet Point 1</BulletPoint>
<BulletPoint>Example Bullet Point 2</BulletPoint>
<MSRP currency="USD">25.19</MSRP>
<Manufacturer>Example Product Manufacturer</Manufacturer>
<ItemType>example-item-type</ItemType>
</DescriptionData>
<ProductData>
<Health>
<ProductType>
<HealthMisc>
<Ingredients>Example Ingredients</Ingredients>
<Directions>Example Directions</Directions>
</HealthMisc>
</ProductType>
</Health>
</ProductData>
</Product>
</Message>
</AmazonEnvelope>';
// $requestXml = trim($requestXml); // doesn't help
// $requestXml = preg_replace('/[[:^print:]]/', '', $requestXml);
// $requestXml = preg_replace('/^(\xEF\xBB\xBF)/', '', $requestXml);
$response = Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8'
])->put($url, [
'body' => $requestXml
]);
I hope so that someone can help me, because I'm going crazy, because few days I can't fix this and it is important.
I tried everything that I found on internet, read everything on Stackoverflow and nothning solved my problem.
Also I tried to call it from file (that I saved through Notepad++ as UTF-8)
$prefixAmazon = Storage::disk('amazon')->getDriver()->getAdapter()->getPathPrefix();
$requestXml = file_get_contents($prefixAmazon . 'createFeed.xml');
I found solution for this create product feed in Laravel with Amazon SP-API (https://github.com/amazon-php/sp-api-sdk):