1
votes

I am using Amazon MWS CreateInboundShipmentPlan to create shipment plan and it is working quite good if I limit my product under 23-24 but If I try to submit more than 24 it gives me InvalidAddress error. I am using PHP API to submit a request to Amazon MWS. In initial troubleshoot I think its all about the URL length because if I increase the URL length by adding more SKU's it starts giving problem.

  1. If I try with limited number of SKU's I get successful result.
  2. But if I try with more SKU's it gives me

    [Error] => Array ( [Type] => Sender [Code] => InvalidAddress [Message] => Resource /errors/mws.amazonservices.com/500.html is not found on this server. )

Here is my PHP code.

function amazon_CreateInboundShipmentPlan($amazonAWSAccessKeyId,$amazonSellerId,$amazonMWSAuthToken,$amazonMarketPlaceId,$amazonSecretKey,$domain,$extras){
    $param = array();
    $param['AWSAccessKeyId']     = $amazonAWSAccessKeyId;
    $param['Action']             = 'CreateInboundShipmentPlan';
    $param['SellerId']           = $amazonSellerId;
    $param['MWSAuthToken']       = $amazonMWSAuthToken;
    $param['SignatureMethod']    = 'HmacSHA256';
    $param['SignatureVersion']   = '2';
    $param['Timestamp']          = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
    $param['Version']            = '2010-10-01';
    $param = array_merge($param,$extras);

    $secret = $amazonSecretKey;

    $url = array();
    foreach ($param as $key => $val) {

        $key = str_replace("%7E", "~", rawurlencode($key));
        $val = str_replace("%7E", "~", rawurlencode($val));
        $url[] = "{$key}={$val}";
    }

    $amazon_feed = '';

    sort($url);

    $arr   = implode('&', $url);

    $sign  = 'POST' . "\n";
    $sign .= 'mws.amazonservices.'.$domain.'' . "\n";
    $sign .= '/FulfillmentInboundShipment/'.$param['Version'].'' . "\n";
    $sign .= $arr;

    $signature      = hash_hmac("sha256", $sign, $secret, true);
    $httpHeader     =   array();
    $httpHeader[]   =   'Transfer-Encoding: chunked';
    $httpHeader[]   =   'Content-Type: application/xml';
    $httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
    $httpHeader[]   =   'Expect:';
    $httpHeader[]   =   'Accept:';

    $signature      = urlencode(base64_encode($signature));

    $link  = "https://mws.amazonservices.".$domain."/FulfillmentInboundShipment/".$param['Version']."?";
    $link .= $arr . "&Signature=" . $signature;

    echo strlen($link)."\n";

    $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    $errors=curl_error($ch);
    curl_close($ch);

    $xml = simplexml_load_string($response);
    $json = json_encode($xml);
    $array = json_decode($json,TRUE);
    return $array;
     }

I think there is some problem with the URL length. Please help me to figure out what's exactly wrong with this code.

1

1 Answers

0
votes

I finally figure out the problem. Its a url limit problem I changed my method of posting data from GET to POST and it resolved the issue.