amz-tools / amazon-sp-api

Amazon Selling Partner API Client
MIT License
238 stars 121 forks source link

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

Closed doverradio closed 2 years 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. Using PRODUCT, I made the getDefinitionsProductType call and got 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.

amz-tools commented 2 years ago

Hi @doverradio,

you mentioned you already tried the patchListingsItem call as described in this issue. Could you post that as well? Currently I can only see two putListingsItem calls, which is actually, according to the docs, used to create or fully update a listing:

Creates a new or fully-updates an existing listings item for a selling partner.

So patchListingsItem is definitely the right operation if you only want to update price and quantity. An alternative way of updating would be by uploading a feed. A bit old fashioned, but it should work as well. You can see an example of how to update the quantity of an SKU via a feed here in our docs.

doverradio commented 2 years ago

Hello,

I tried to upload a feed following the feed instructions in your docs and was successful in updating the quantity.

But what about price?

I tried to add a price to the POST_INVENTORY_AVAILABILITY_DATA call but it did not update it on the listing.

How can I update the price? Is POST_INVENTORY_AVAILABILITY_DATA not correct to make the price change?

Please show me an example that you use when updating your price via feed API.

amz-tools commented 2 years ago

You should be able to update the price by using POST_PRODUCT_PRICING_DATA, here is a link to the schema.

Alternatively you could also use POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA, which should make it even easier for you. Instead of an XML it only expects sku, quantity and/or price as tab-delimited headers in the first line and then the corresponding values (also tab-delimited) in the next line(s).

doverradio commented 2 years ago

Thank you so much for this.

Lastly, I want to "bulk list" to a bunch of ASINS I have in a list. Literally I want to just put a price and quantity.

What is the proper feed/way to accomplish this?

I have around 350k ASINS.

amz-tools commented 2 years ago

That's basically up to you, all of the ways support bulk update:

patchListingsItem operation supports an array of patches, but I couldn't find out the max length of it.

POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA also allows you to update multiple SKUs at once (line by line), also couldn't find the maximum lines in one feed, if there is a limit at all.

POST_INVENTORY_AVAILABILITY_DATA and POST_PRODUCT_PRICING_DATA also allow you to bulk update by adding multiple <Message> blocks, but I think these have a maximum of 20 per feed upload.

doverradio commented 2 years ago

What about POST_FLAT_FILE_INVLOADER_DATA?

I am getting this from FeedType enumeration of old Amazon MWS documentation.

It states "For creating or updating listings for products already in Amazon's catalog."

Previously, I really had my hopes pinned on this one being the "bulk lister" but constantly got rejected because of the column headers being rejected. Due to that I was trying to look for a workaround but these would be not updating SKUs but actually creating new SKUs.

Which feed enumeration type upload allows one to create new SKUs?

I suppose is my real question for you.

amz-tools commented 2 years ago

Yes, you should be able to do so with POST_FLAT_FILE_INVLOADER_DATA. Alternatively this should also be possible with putListingsItem or with the JSON_LISTINGS_FEED, which is actually the same data format as putListingsItem, but uploaded as a feed.

doverradio commented 2 years ago

Massive win! Got it to post 10 skus via POST_FLAT_FILE_INVLOADER_DATA. Will have to play around with putListingsItem or JSON_LISTINGS_FEED.

Would be super helpful if, in future, there were examples covering how to use those calls.

Thanks so much!

amz-tools commented 2 years ago

@doverradio,

great! Yes, we will put this on our list to cover some examples of the most common use cases in the nearer future in the README.