Goose
Goose

Reputation: 4821

Using Amazon MWS Merchant Fulfilment API PHP SDK to buy shipping

I am attempting to use the Amazon MWS Merchant Fulfilment API PHP SDK to buy shipping.

https://developer.amazonservices.com/doc/merchantfulfillment/merchantfulfillment/v20150601/php.html/132-2116251-7478560

My code looks something like this, with some personal details changed for privacy:

// Configure
require_once('sdks/Amazon/.config.inc.php');
$serviceUrl = "https://mws.amazonservices.com/MerchantFulfillment/2015-06-01";
$config = array(
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3
);


// Create service
$merchant_service = new Amazon_Merchant_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config);

// Create request object
$request = new Amazon_Merchant_Model_CreateShipmentRequest();

// Set SellerId
$request->setSellerId(MERCHANT_ID);

// Define shipping info
$package_dimensions = array(
    'Length' => 5,
    'Width' => 5,
    'Height' => 5,
    'Unit' => 'inches',
);
$weight = array(
    'Value' => 5,
    'Unit' => 'ounces',
);
$ship_from_address = array(
    'Name' => '904Custom',
    'AddressLine1' => 'foobar',
    'AddressLine2' => 'foobar',
    'Email' => '[email protected]',
    'City' => 'foobar',
    'StateOrProvinceCode' => 'FL',
    'PostalCode' => '12345',
    'CountryCode' => 'US',
    'Phone' => '(888) 555-5555',
);
$shipping_service_options = array(
    'DeliveryExperience' => 'DeliveryConfirmationWithoutSignature',
    'CarrierWillPickUp' => true,
);
$shipping_details_array = array(
    'AmazonOrderId' => '114-1234567-1234567',
    'SellerOrderId' => '114-1234567-1234567',
    'ShipFromAddress' => $ship_from_address,
    'PackageDimensions' => $package_dimensions,
    'Weight' => $weight,
    'ShippingServiceOptions' => $shipping_service_options,
);
$request->setShipmentRequestDetails($shipping_details_array);

// Set shipping service id
$request->setShippingServiceId('1234');

// Invoke request
// invokeCreateShipment is a wrapper for $service->CreateShipment($request);
$result = $this->invokeCreatehipment($merchant_service, $request);

This gives me

Fatal error: Call to a member function _toQueryParameterArray() on a non-object in /var/www/hydra/sdks/Amazon/Merchant/Model.php on line 276

The details may not be correct, but right now I'm only trying to send a request to the API, which the SDK isn't allowing me to do because of the fatal PHP error it's running into. For what it might be worth, I removed $request->setShipmentRequestDetails() to see what result I would get. I did get a response from the API, but it was a InternalFailure XML:

<ErrorResponse xmlns="https://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
    <Error>
        <Type>Receiver</Type>
        <Code>InternalFailure</Code>
    </Error>
    <RequestId>b1f5a04c-54ac-442c-ab88-f2f1c9374377</RequestId>
</ErrorResponse>

I've read all of the following documentation

I've viewed the sample files included in the SDK, but they aren't complete examples.

I've done exhaustive googling, but can't find any usage of this SDK in the wild.

http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Overview.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_HowToUseForPrime.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_CreateShipment.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Datatypes.html#ShipmentRequestDetails http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Datatypes.html#ShippingServiceOptions

I've trying var_dump()ing in the source code to try to figure out what's going on, but it's very abstract and difficult to work with. For instance, toQueryParameterArray() calls _toQueryParameterArray() which calls __toQueryParameterArray() which calls both _toQueryParameterArray() and __toQueryParameterArray(). The code is difficult to understand and attempts to code a workaround have fallen flat.

For reference, here is a mirror of the official Amazon MWS Merchant Fulfilment API PHP SDK

https://github.com/AustinMaddox/mws-merchant-fulfillment-php-client-library

I've used the Orders, Feed, and Reports API in dozens of ways for years now, but on the Merchant API, I am stumped and I need some help.

How can I use the Amazon MWS Merchant Fulfilment API PHP SDK to buy shipping?

Upvotes: 1

Views: 1199

Answers (1)

Goose
Goose

Reputation: 4821

Thanks to Bullcom over on the Amazon forums, I figured it out.

I needed to create objects and use setter and getters, not just pass arrays of data

So my new code looks more like this

    $shipping_details = new Amazon_Merchant_Model_ShipmentRequestDetails();
    $weight = new Amazon_Merchant_Model_Weight();
    $weight->setValue(5);
    $weight->setUnit('ounces');
    $shipping_details->setWeight($weight);

This should definitely be in the sample folder for the SDK, rather than vague the comment that they currently have "// object or array of parameters"

Upvotes: 2

Related Questions