double-break / spapi-php

Amazon Selling Partner API PHP Client
MIT License
56 stars 48 forks source link

Submitting inventory feed keeps returning 5001 error when stock goes above 100 #21

Closed bastiaansenglenn closed 3 years ago

bastiaansenglenn commented 3 years ago

Hello,

Today I encountered a problem when submitting an inventory feed. All calls did not return an error if you just kept the stock between 10 and 99. The solution for submitting stock under 10 was to place a leading 0(e.g. 5 would be 05).

I did not find a solution for stock above 99.. The error i encountered;

 "Result" => array:4 [
        "MessageID" => "0"
        "ResultCode" => "Error"
        "ResultMessageCode" => "5001"
        "ResultDescription" => "XML Parsing Fatal Error at Line 16, Column 18: Content is not allowed in trailing section. Content is not allowed in trailing section."
      ]

This is my XML that i submit as feed document;

<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.01</DocumentVersion>
        <MerchantIdentifier>*******</MerchantIdentifier>
    </Header>
    <MessageType>Inventory</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Inventory>
            <SKU>SKU1</SKU>
            <Quantity>110</Quantity>
        </Inventory>
    </Message>  
</AmazonEnvelope>

I use the Feeder() class to submit my file, is there an encoding problem in my case?

Thanks in advance!

mridulmahajanin commented 3 years ago

@bastiaansenglenn I am getting same error even for quantity 18 here is my xml can you please share how you solved it for quantity greater then 10 ?

<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.01</DocumentVersion>
        <MerchantIdentifier>AKIA5PDDPQHDGOZBCWXJ</MerchantIdentifier>
    </Header>
    <MessageType>Inventory</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Inventory>
            <SKU>5025574004853</SKU>
            <Quantity>18</Quantity>
        </Inventory>
    </Message>
</AmazonEnvelope>
madhupatel-hub commented 3 years ago

@lyubo-slavilov I'm facing the same problem and not able to update my inventory with any number of quantity can you please help me to find out what I'm doing wrong. This is my XML code:

<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.01</DocumentVersion>
        <MerchantIdentifier>*********</MerchantIdentifier>
    </Header>
    <MessageType>Inventory</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Inventory>
            <SKU>Z1-DVHW-8B5D</SKU>
            <Quantity>05</Quantity>
        </Inventory>
    </Message>  
</AmazonEnvelope>

My content type:

// content type of the feed data to be uploaded. $contentType = 'text/xml; charset=UTF-8';

// create feed document $feedClient = new \DoubleBreak\Spapi\Api\Feeds($cred, $config); $response = $feedClient->createFeedDocument(["contentType" => $contentType]); $payload = $response['payload']; print_r($payload); $feedContentFilePath = 'inventory_update.xml';

$result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$feedContentFilePath); print_r($result);

Getting error: Array ( [Header] => Array ( [DocumentVersion] => 1.02 [MerchantIdentifier] => ***) [MessageType] => ProcessingReport [Message] => Array ( [MessageID] => 1 [ProcessingReport] => Array ( [DocumentTransactionID] => 50022018690 [StatusCode] => Complete [ProcessingSummary] => Array ( [MessagesProcessed] => 0 [MessagesSuccessful] => 0 [MessagesWithError] => 1 [MessagesWithWarning] => 0 ) [Result] => Array ( [MessageID] => 0 [ResultCode] => Error [ResultMessageCode] => 5001 [ResultDescription] => XML Parsing Fatal Error at Line 16, Column 18: Content is not allowed in trailing section. Content is not allowed in trailing section. ) ) ) ) Thanks in Advance! Madhu Patel

mridulmahajanin commented 3 years ago

@madhupatel-hub In ASECryptoStream.php there is method getPaddedText that is called when encrypt method is called from uploadFeedDocument method of feeder class just comment it out in encrypt method it adds extra text in xml check attached screenshot it will work afterwards

madhupatel-hub commented 3 years ago

Thank You soooooooo much @mridulmahajanin.It's working for me.

lyubo-slavilov commented 3 years ago

@madhupatel-hub In ASECryptoStream.php there is method getPaddedText that is called when encrypt method is called from uploadFeedDocument method of feeder class just comment it out in encrypt method it adds extra text in xml check attached screenshot it will work afterwards

Next time we update the lib, the suggested changes would be wiped out. Do you think we can came up with more durable solution?

madhupatel-hub commented 3 years ago

Yes @lyubo-slavilov you can wiped out the suggested changes from the library that would be good for all users. Because it's very difficult to find out this kind of issues for everyone. I'm currently using it. if I found anything else, I'll let you know.to make this library better. And thanks for understanding the concern. Madhu Patel

lyubo-slavilov commented 3 years ago

@mridulmahajanin Is it safe to remove this getPaddedText () method call forom the lib?

mridulmahajanin commented 3 years ago

@lyubo-slavilov Yep its totally safe its just adding extra padded text in XML i think AESEncryption library that you guys are using is used for other purposes as well but in our context its adding extra content in encrypted XML which in turn is a big problem either you can remove it or write a new encrypt function something like encryptXML and in that function you can copy existing encrypt function removing getPaddedText call that will be even more safe as of now i am looking for finding solution for @madhupatel-hub issue of 5001 issue if stock is above two digits will comment it down if i found a solution :)

lyubo-slavilov commented 3 years ago

I think this issue was resolved while ago. I am going to close it.