amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
586 stars 730 forks source link

Listings API putListingsItem How To Update price and quantity? #419

Closed doverradio closed 4 months ago

doverradio commented 2 years ago

All I want to do is use the Amazon SP-API Listings API's putListingsItem call to update the price and quantity of an item I have listed.

productType

According to the ListingsItemPutRequest docs, productType and attributes are required for this call.

Firstly, to obtain the correct productType value, you are supposed to search for a product definitions type using the Product Type Definitions API. So, I do that, and call searchDefinitionsProductTypes, just to discover my product has no matching product type.

Ultimately, I gave the value PRODUCT for productType field. As a result, the getDefinitionsProductType call returned an object containing an array of propertyNames, shown below:

        "propertyNames": [
            "skip_offer",
            "fulfillment_availability",
            "map_policy",
            "purchasable_offer",
            "condition_type",
            "condition_note",
            "list_price",
            "product_tax_code",
            "merchant_release_date",
            "merchant_shipping_group",
            "max_order_quantity",
            "gift_options",
            "main_offer_image_locator",
            "other_offer_image_locator_1",
            "other_offer_image_locator_2",
            "other_offer_image_locator_3",
            "other_offer_image_locator_4",
            "other_offer_image_locator_5"
        ]
    },

On seeing this, I decide list_price and fulfillment_availability must be the price and quantity and then try using these in my code below.

attributes

The attributes value is also required. However, their current docs show no clear example of what to put for these values, which are where I must put price and quantity somewhere.

I found this link about patchListingsItem and tried to implement that below but got an error.

code:

// trying to update quantity... failed.

    a.response =  await a.sellingPartner.callAPI({
        operation:'putListingsItem',
        path:{
          sellerId: process.env.SELLER_ID,
          sku: `XXXXXXXXXXXX`
        },
        query: {
          marketplaceIds: [ `ATVPDKIKX0DER` ]
        },
        body: {
          "productType": `PRODUCT`
          "requirements": "LISTING_OFFER_ONLY",
          "attributes": {
                "fulfillment_availability": {
                    "fulfillment_channel_code": "AMAZON_NA",
                            "quantity": 4,
                            "marketplace_id": "ATVPDKIKX0DER"
                        }
                    }
      });

    console.log( `a.response: `, a.response )

error:

{
    "sku": "XXXXXXXXXXXX",
    "status": "INVALID",
    "submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
    "issues": [{
        "code": "4000001",
        "message": "The provided value for 'fulfillment_availability' is invalid.",
        "severity": "ERROR",
        "attributeName": "fulfillment_availability"
    }]
}

I also tried using list_price :

// list_price attempt... failed.

    a.response =  await a.sellingPartner.callAPI({
        operation:'putListingsItem',
        path:{
          sellerId: process.env.SELLER_ID,
          sku: `XXXXXXXXXXXX`
        },
        query: {
          marketplaceIds: [ `ATVPDKIKX0DER` ]
        },
        body: {
          "productType": `PRODUCT`
          "requirements": "LISTING_OFFER_ONLY",
          "attributes": {
                "list_price": {
                    "Amount": 90,
                    "CurrencyCode": "USD"
                }
      });

    console.log( `a.response: `, a.response )

Error (this time seems I got warmer... maybe?):


{
    "sku": "XXXXXXXXXXXX",
    "status": "INVALID",
    "submissionId": "34e1XXXXXXXXXXXXXXXXXXXX",
    "issues": [{
        "code": "4000001",
        "message": "The provided value for 'list_price' is invalid.",
        "severity": "ERROR",
        "attributeName": "list_price"
    }]
}

How do you correctly specify the list_price or the quantity so this call will be successful?

Just tryin to update a single item's price and quantity.

smtlaissezfaire commented 1 year ago

As a reference, https://github.com/amzn/selling-partner-api-models/issues/419 helped me immensely. Here are a few gotchas:

Gotcha 1: I'm in ruby and using the ruby-money gem.

puts 22.95.to_money.amount => "USD" but 22.95.to_money.amount.inspect != "USD"

Gotcha 2: "value_with_tax": f"{price:.2f}" f"..." is a python format string, not value_with_tax: { price: ... }

So you'd want something like:

{ value_with_tax: 22.95.to_money.to_f.to_s } or: { value_with_tax: "22.95" }

Gotcha 3: I needed value_with_tax, not value even though I'm in the U.S.

doverradio commented 1 year ago

@sweetdream34310

Unfortunately, I am not currently listing to those marketplaces in EU and if there are discrepancies from the USA version, I would not be giving the proper advice. However, tomorrow I will try and see if I can find a solution for you.

Twoandfrommike commented 1 year ago

ok you can use the class from https://github.com/jlevers/selling-partner-api but you 'll need to create php array and objects that follow the structure of @tbrains sugestions.

BUT... where do you get all the paths from ? ex: /attributes/item_name ???

ex: code:

$patches = array(new stdClass());
$patches[0]->op = "replace";
$patches[0]->path = "/attributes/item_name";
$patches[0]->value = array(new stdClass());
$patches[0]->value[0]->value = "Your product new name";
$patches[0]->value[0]->language_tag = "en_US";
$patches[0]->value[0]->marketplace_id = "marketplace_id ";

$body = new \SellingPartnerApi\Model\ListingsV20210801\ListingsItemPatchRequest(['product_type'=>"Product", 'patches'=>$patches]);
cuizheng0520 commented 1 year ago

list_price

Quantity is similar, you have to patch the attribute fulfillment_availability,

fulfillment_channel_code = "DEFAULT"  # MFN

patch_data = {
    "productType":
    "PRODUCT",
    "patches": [{
        "op": "replace",
        "path": "/attributes/fulfillment_availability",
        "value": [{
            "fulfillment_channel_code": fulfillment_channel_code,
            "quantity": quantity
        }]
    }]
}

help!! no matter how I debug, it still doesn't work, I can't find the error, please help

request: {"productType":"PRODUCT","patches":[{"op":"REPLACE","path":"/attributes/fulfillment_availability","value":[{"quantity":123,"fulfillment_channel_code":"DEFAULT"}]}]}

response: class ListingsItemSubmissionResponse { sku: XBV001234 status: INVALID submissionId: 88f30c7a6619435b8892ceb03b2659e3 issues: [class Issue { code: 99022 message: The field 'fulfillment_channel_code' for the attribute 'fulfillment_availability' does not have enough values. The required minimum is '1' value(s). severity: ERROR attributeName: fulfillment_availability }] }

sgeorgiev1995 commented 1 year ago

{"productType":"PRODUCT","patches":[{"op":"REPLACE","path":"/attributes/fulfillment_availability","value":[{"quantity":123,"fulfillment_channel_code":"DEFAULT"}]}]}

try using "replace" instead of "REPLACE"

kstar0102 commented 1 year ago
Sorry to bother you.

I have tested my following code without sellingPartner package.

----------
def patch_listings_item(api_url, seller_id, sku, access_token):
    url = f"{api_url}/listings/2021-08-01/items/{seller_id}/{sku}"
    headers = {
        "Accept": "application/json",
        "x-amz-access-token": f"{access_token}",
        "Content-Type": "application/json; charset=utf-8",
    }
    payload = {
        "productType": "PRODUCT",
        "patches": [
            {
                "op": "replace",
                "path": "/attributes/fulfillment_availability",
                "value": [
                    {
                        "fulfillment_channel_code": "DEFAULT",
                        "quantity": 1,
                        "lead_time_to_ship_max_days": 5,
                        "marketplace_id": "A1VC38T7YXB528",
                    }
                ],
            }
        ],
    }
    params = {"marketplaceIds": ["A1VC38T7YXB528"], "issueLocale": "ja_JP"}
    response = requests.patch(url, headers=headers, data=payload, params=params)
----------

but result is ;
Failed to patch the listing item. Error: {'errors': [{'code': 'InvalidInput', 'message': 'Could not process payload', 'details': ''}]}
-----

Could you help me with your high amz sp api skill ?

Thank you
Javadebi commented 11 months ago

I know it's not relevant to this question, but may I ask how you guys extract these object structures from the schema? I mean programmatically?

dev-pecaagora commented 10 months ago

I receive an accept but nothing changes on Amazon, it's been more than 2 hours help me

Robinhood2009 commented 6 months ago

@tbrains @BashaBill

Hello! I am trying to use putListingsItem but I can't figure out what the body should look like. The example given in the documentation does not work. If anyone could help that would be amazing this is what I have currently: image

steven-so commented 6 months ago

@tbrains thank you list_price update success Must have the following format, which is different from purchasable_offer. {"productType":"PRODUCT","patches":[{"op":"replace","path":"/attributes/list_price","value":[{"currency":"USD","marketplace_id":"ATVPDKIKX0DER","value":14.98}]}]}

Thanks for sharing this find.

Does anyone know if changing "List Price" through xml also works? I've tried changing MaximumRetailPrice through the feed but that didn't seem to work.

dialdhruv commented 5 months ago

How to update maximum retail price (MRP) ?

chapmanjw commented 5 months ago

How to update maximum retail price (MRP) ?

@dialdhruv See this answer: https://github.com/amzn/selling-partner-api-models/issues/1289

qdev89 commented 4 months ago

hi guys, I'm really stuck on fileld merchant_suggested_asin, it's a required filed for a product type definitions (TEMPORARY_TATTOO) but I don't know how to fill it to complete my API call.

  1. If I put "merchant_suggested_asin": [ { "value": "WPID||ASIN" } ], It will return as issue on "issues": [ { "code": "8105", "message": "The data you provided for an attribute is invalid. Please refer the data definitions and resubmit with a valid value.", "severity": "ERROR", "attributeNames": [ "merchant_suggested_asin" ], "categories": [ "INVALID_ATTRIBUTE" ] } ],

    1. If I put a random number on this, it will return issue as : "code": "8541", "message": "The Listing data provided is different from what's already in the Amazon catalog. The item_id provided matches ASIN 0000000000, but some of the listing data contradicts what is already in the Amazon catalog. The following listing attribute value(s) conflict with Amazon catalog value(s): 'item_name' (Merchant [\"100 PCS Two Fast Race Car Temporary Tattoos Stickers Theme 2nd Birthday Party Decorations Favors Supplies Decor 2 Fast Racing Checkered Tattoo Sticker Gifts For Boys Girls School Prizes Carnival\"] / Amazon [en_US: \"Finding Peaches in the Desert\", en_IN: \"Special Education Teachers Kit: The Cartography of Syntactic Structures, Volume 6\", en_GB: \"Ksiega Diny: The Cartography of Syntactic Structures, Volume 6 (Äldre Svenska Frälsesläkter)\" and 19 other variant(s) en_SG, en_CA, en_AE, en_AU, nl_NL, de_DE, fr_FR, pl_PL, es_ES, hi_IN, zh_CN, ja_JP, es_MX, fr_BE, pt_BR, sv_SE, it_IT, ar_AE, tr_TR]), 'customer_id' (Merchant [\"692323389502\"] / Amazon []). To fix the issue, please follow these steps 1) If the product you are listing is the same as 0000000000, then update your listing's 'item_name, customer_id' attribute(s) to match Amazon's catalog value, 2) If it's not the right ASIN, make sure the item_id provided is correct, or 3) If you disagree with the data in Amazon catalog contact Selling Partner Support to start the appeal process.", "severity": "ERROR",

      3.  MY question is : how do I put it's as null because I want to listing a new listing that doesn't have exist item on it. 
      as scheme show as 
      
      ` "merchant_suggested_asin": {
      "title": "Merchant Suggested ASIN",
      "description": "Provide an ASIN for your product if one exists. If a value is not provided, the system will attempt a match based on the External Product ID.",
      "examples": [
          "B007KQBXN0"
      ],
      "type": "array",
      "minItems": 1,
      "minUniqueItems": 1,
      "maxUniqueItems": 1,
      "selectors": [
          "marketplace_id",
          "value"
      ],
      "items": {
          "type": "object",
          "required": [
              "marketplace_id",
              "value"
          ],
          "properties": {
              "value": {
                  "title": "Merchant Suggested ASIN",
                  "description": "Provide an ASIN for your product if one exists. If a value is not provided, the system will attempt a match based on the External Product ID.",
                  "editable": false,
                  "hidden": false,
                  "examples": [
                      "B007KQBXN0"
                  ],
                  "type": "string",
                  "minLength": 10,
                  "maxLength": 10,
                  "maxUtf8ByteLength": 40
              },
              "marketplace_id": {
                  "$ref": "#/$defs/marketplace_id"
              }
          },
          "additionalProperties": false
      }

      },`

      So it supposes can be empty but looks like it's abut from SP API Listing.

      Please help me on this. Thank you

gabiRojas1978 commented 4 months ago

Hello. How I can update the Recommended Retail Price (RRP) or a Manufacturer’s Suggested Retail Price (MSRP)?

steven-so commented 4 months ago

@xiaoyu-tamu, right now its not possible to update the business price via Listing API.

Is this still the case?

I've looked at the json schema trying to find anything that could be the business price (B2B), but I have been unsuccessful.

It would be super useful if I could update the business price through patchListingsItem instead of the xml feed.