Search code examples
phpamazon-selling-partner-api

Not able to update the inventory stock with patch/put listing Amazon SP API with PHP


I need your help, I tried all the mentioned suggestions (https://github.com/amzn/selling-partner-api-docs/issues/2167) but am still not able to update the inventory quantity with Amazon SP API.

I am trying to update the quantity stock without Feeds.

Below body, I am sending to update the quantity with Put Request.

The package I am using is: https://github.com/jlevers/selling-partner-api

SellingPartnerApi\Model\ListingsV20210801\ListingsItemPutRequest Object
(
    [container:protected] => Array
        (
            [product_type] => FALSE_EYELASH
            [requirements] => 
            [attributes] => Array
                (
                    [fulfillment_availability] => Array
                        (
                            [fulfillment_channel_code] => AMAZON_JP
                            [quantity] => 5
                        )
                )
        )
)

When I use sandbox get a response ACCEPTED but without getting an error.

........
            [sku] => 2629-48KGT-2347 // TEST
            [status] => INVALID
            [submission_id] => 602b84b73b964e24b174a80d3a7870a3
            [issues] => Array
                (
                    [0] => SellingPartnerApi\Model\ListingsV20210801\Issue Object
                        (
                            [container:protected] => Array
                                (
                                    [code] => 4000003
                                    [message] => ������������Amazon������������������������������������������������������������������������������
                                    [severity] => ERROR
                                    [attribute_names] => 
                                )
                        )
                )
........

=======================

To patch the request I am trying the below body.

SellingPartnerApi\Model\ListingsV20210801\ListingsItemPatchRequest Object
(
    [container:protected] => Array
        (
            [product_type] => FALSE_EYELASH
            [patches] => Array
                (
                    [op] => replace
                    [operation_type] => UPDATE    // Already try with or without this parameter
                    [path] => /attributes/fulfillment_availability
                    [value] => Array
                        (
                            [fulfillment_channel_code] => AMAZON_JP
                            [quantity] => 5
                        )
                )
        )
)

Get the below response.

Exception when calling: [400] {
  "errors": [
    {
      "code": "InvalidInput",
      "message": "Request has missing or invalid parameters and cannot be parsed.",
      "details": ""
    }
  ]
}

Is there any way to update the order status to shipped without the feeds API?

The code which I try so far is below.

$patchBody = [
    'product_type' => 'BEAUTY',
    'marketplaceIds' => ['A1VC38T7YXB528'], // Already try with or without
    'patches' => [
        [
            "op" => "replace",
            "operation_type" => "PARTIAL_UPDATE",
            "path" => "/attributes/fulfillment_availability",
            "value" => [
                [
                    "fulfillment_channel_code" => 'DEFAULT',
                    "quantity" => 2
                ]
            ]
        ]
    ]
];

$putBody = [
    'product_type' => 'BEAUTY',
    'attributes' => [
        "fulfillment_availability" => [
            "fulfillment_channel_code" => "DEFAULT",
            "quantity" => 2
        ]
    ]
];

$seller_id = 'MY-SELLER-ID';
$sku = '8001025974';
$marketplace_ids = array('A1VC38T7YXB528');

// Update inventory
$apiInstance = new SellingPartnerApi\Api\ListingsV20210801Api($config);

$body = new \SellingPartnerApi\Model\ListingsV20210801\ListingsItemPatchRequest($patchBody);
// $issue_locale = 'en_US';

try {
    $result = $apiInstance->patchListingsItem($seller_id, $sku, $marketplace_ids, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling: ', $e->getMessage(), PHP_EOL;
}

Solution

  • I found the solution the main issue is in the body there are many different methods that are provided by Amazon feed base or listing put/patch base.

    I am using selling partner api

    In my question, I was using the Listing base approach.

    The endpoint URL is below.

    {{fe_url}}/listings/2021-08-01/items/{{seller_id}}/8001025974?marketplaceIds={{jp_market_id}}
    

    The body should be like the below. If there is an error in product type even if you pass the current product type just use "PRODUCT" instead.

    Note: But if you are using a feed document then it might be changed see here

    I got success with the below body.

    {
        "productType": "PRODUCT",
        "patches": [
            {
                "op": "replace",
                "operation_type": "PARTIAL_UPDATE",
                "path": "/attributes/fulfillment_availability",
                "value": [
                    {
                        "fulfillment_channel_code": "DEFAULT",
                        "quantity": 0
                    }
                ]
            }
        ]
    }
    

    The given code is a full example.

    $config = new Configuration([
        "lwaClientId" => "YOUR-CLIENT-ID",
        "lwaClientSecret" => "YOUR-CLIENT-SECRET",
        "lwaRefreshToken" => "YOUR-TOKEN",
        "awsAccessKeyId" => "YOUR-ACCESS-KEY",
        "awsSecretAccessKey" => "YOUR-KEY",
        // If you're not working in the North American marketplace, change
        // this to another endpoint from lib/Endpoint.php
        "endpoint" => Endpoint::FE
    ]);
    
    
    $seller_id = 'YOUR-ID'; // string | A selling partners identifier, such as a merchant account or vendor code.
    $sku = 'YOUR-PRODUCT-CODE'; // string | A selling partner provided identifier for an Amazon listing.
    $marketplace_ids = array('YOUR-MARKET-ID');
    
    
    $patchBody = [
        'product_type' => 'PRODUCT',
        'patches' => [
            [
                "op" => "replace",
                "operation_type" => "PARTIAL_UPDATE",
                "path" => "/attributes/item_name",
                "value" => [
                    [
                        "value" => "【ome】Colorラッシュ・セーブル レッドブラウン Cカール 0.07mm×9mm",
                        "marketplace_id" => "CHANGE-WITH-YOUR-MID"
                    ]
                ],
            ]
        ]
    ];
    
    
    // Update inventory
    $apiInstance = new SellingPartnerApi\Api\ListingsV20210801Api($config);
    
    $body = new \SellingPartnerApi\Model\ListingsV20210801\ListingsItemPatchRequest($patchBody);
    
    print_r($body);
    
    try {
         $result = $apiInstance->patchListingsItem($seller_id, $sku, $marketplace_ids, $body);
         print_r($result);
    } catch (Exception $e) {
         echo 'Exception when calling: ', $e->getMessage(), PHP_EOL;
    }