SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Seller Central SOAP API & PHP problems??

    Hello forums!!
    I am using Amazon's seller central SOAP API for posting documents (inventory uploads, price updates, stock updates etc.) with PHP5 as platform.
    I am using PEAR::SOAP library for consuming SOAP services(As PEAR::SOAP supports MIME attachments while PHP5 SOAP extension doesn't).
    After many trials and struggle I got succeed on uploading the XML feeds(for stock updates).But when i tried to check the inventory upload error log(with the TransactionID returned during upload) i got an error.

    Code Details

    XML Feed(stock.xml):
    Code XML:
    <?xml version="1.0"?>
    <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    	<Header>
    		<DocumentVersion>1.01</DocumentVersion>
    		<MerchantIdentifier>your_seller_central_merchant_id</MerchantIdentifier>
    	</Header>
    	<MessageType>Inventory</MessageType>
    	<Message>
    		<MessageID>1</MessageID>
    		<OperationType>Update</OperationType>
    		<Inventory>
    			<SKU>PRODUCT_SKU_123</SKU>
    			<Quantity>10</Quantity>
    		</Inventory>
    	</Message>
    </AmazonEnvelope>

    PHP Code used for posting document:
    Code PHP:
    <?php
    ################################################################
    # Using PEAR::SOAP - Start
    ################################################################
    require_once('SOAP/Client.php');
    require_once("SOAP/Value.php");
     
    $proxy 		= array('user' => 'your_seller_central_email', 'pass' => 'your_seller_central_pass');
    $merchant 	= array('merchantIdentifier' => 'your_seller_central_merchant_id', 'merchantName' => 'your_seller_central_merchant_name'); 
    $client 	= new SOAP_Client('https://merchant-api.amazon.co.uk/gateway/merchant-interface-mime', true, false, $proxy);
     
    $doc 			= new SOAP_Attachment('doc', 'text/xml', dirname(__FILE__) .'/stock.xml');
    $method 		= 'postDocument';
    $messageType 	= '_POST_INVENTORY_AVAILABILITY_DATA_';
     
    $params 	= array('merchant' => $merchant, 'messageType' => $messageType, 'doc' => $doc);
    $options 	= array('attachments'=>'Mime');
     
    $response 	= $client->call($method, $params, $options);
    if(PEAR::isError($response)){
    	echo 'Code::'.$response->getCode().'<br />Error::'.$response->getMessage();
    }else{
    	print_r($response);
    }
    ################################################################
    # Using PEAR::SOAP - End
    ################################################################
    ?>

    ERROR returned while checking for inventory upload error log:
    Code XML:
    <?xml version="1.0"?>
    <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
        <Header>
            <DocumentVersion>1.02</DocumentVersion>
            <MerchantIdentifier>your_seller_central_merchant_id</MerchantIdentifier>
        </Header>
        <MessageType>ProcessingReport</MessageType>
        <Message>
            <MessageID>1</MessageID>
            <ProcessingReport>
                <DocumentTransactionID>XXXXXXX</DocumentTransactionID>
                <StatusCode>Complete</StatusCode>
                <ProcessingSummary>
                    <MessagesProcessed>0</MessagesProcessed>
                    <MessagesSuccessful>0</MessagesSuccessful>
                    <MessagesWithError>0</MessagesWithError>
                    <MessagesWithWarning>0</MessagesWithWarning>
                </ProcessingSummary>
                <Result>
                    <MessageID>0</MessageID>
                    <ResultCode>Error</ResultCode>
                    <ResultMessageCode>5000</ResultMessageCode>
                    <ResultDescription>Line Number: 1 Column Number: 1 Error Message: Invalid document structure</ResultDescription>
                </Result>
            </ProcessingReport>
        </Message>
    </AmazonEnvelope>

    Note: Previoulsy I tried with AIM API but couldn't succeed which only returned 'Invalid Input' error.
    Later I came to know that AIM doesn't work for posting documents for seller central accounts,
    and Seller Central SOAP API works good for posting documents(sample code of C# and JAVA has also been mentioned in the seller central help section).
    I have Seller Central Account for UK.

    I browsed the amazon forums and came to know that nobody has accomplished the task of posting documents successfully with PHP either using AIM and SOAP. Though fetching documents from Amazon works great with both APIs.

    Finally::Can anybody can point out the error in my process/code?
    Thanks in advance for the valueable tips/suggestions.

    Thanks
    Best Regards
    PHPycho

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I'd get something like fiddler so you can snag a copy of the outgoing message and see exactly what is going on on the wire before doing anything rash.

    Also, I'm not sure if PEAR:SOAP handles this, but I'd make sure it handles proper character encoding. SOAP (in most cases) rides on XML and needs to be valid XML before anything.

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i printed the $doc as print_r($doc), i got the following:

    SOAP_Attachment Object
    (
    [value] =>
    [nqn] => QName Object
    (
    [name] => doc
    [ns] =>
    [namespace] =>
    )

    [name] => doc
    [namespace] =>
    [tqn] =>
    [type] =>
    [type_namespace] =>
    [arrayType] =>
    [attributes] => Array
    (
    [href] => cid:a6a62fe5e183162d5273424edaa87246
    )

    [options] => Array
    (
    [attachment] => Array
    (
    [body] => <?xml version="1.0"?><AmazonEnvelope xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"> <Header> <DocumentVersion>1.01</DocumentVersion> <MerchantIdentifier>your_seller_central_merchant_id</MerchantIdentifier> </Header> <MessageType>Inventory</MessageType> <Message> <MessageID>1</MessageID> <OperationType>Update</OperationType> <Inventory> <SKU>PRODUCT_SKU_123</SKU> <Quantity>10</Quantity> </Inventory> </Message></AmazonEnvelope>

    [disposition] => stock.xml
    [content_type] => text/xml
    [encoding] => base64
    [cid] => a6a62fe5e183162d5273424edaa87246
    )

    )

    )

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Well, it looks like the object data is reflecting the XML properly at least. Not sure why it isn't populated, but I'd start looking at the request side of things.

  5. #5
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Has anyone managed to upload files to Amazon Seller Central with PHP5 yet?

    ANY suggestions or working code samples would be useful.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •