Amazon SP-API Listings API putListingsItem 如何更新价格和数量? Node.js

发布于 2025-01-18 10:25:40 字数 4897 浏览 1 评论 0原文

我正在使用 amazon-sp-api (亚马逊销售合作伙伴的 JavaScript 客户端API)但这不仅限于此客户端。我想做的就是使用 Amazon SP-API Listings API 的 putListingsItem 调用 来更新我列出的商品的价格和数量。

productType

根据ListingsItemPutRequest 文档、productTypeattributes

首先,要获取正确的 productType 值,您应该使用 产品类型定义 API。因此,我这样做,并调用 searchDefinitionsProductTypes,只是为了发现我的产品没有匹配的产品类型。

最终,我为 productType 字段指定了值 PRODUCT。使用 PRODUCT,我进行了 getDefinitionsProductType 调用,并获得了一个包含 propertyNames 数组的对象,如下所示:


            "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"
            ]
        },

看到这一点,我决定 list_pricefulfillment_availability 必须是价格数量,然后尝试在下面的代码中使用它们。

属性

属性值也是必需的。然而,他们当前的文档没有显示明确的示例来说明如何为这些值添加内容,而我必须将价格和数量放在某处。

我找到了关于 patchListingsItem 的链接,并尝试在下面实现它但出现错误。

代码:

// 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 )

错误:

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

我也尝试使用 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 )

错误(这次似乎我变得更温暖了......也许?):

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

如何正确指定 list_price 或数量,以便此调用成功?

只是尝试更新单个商品的价格和数量。

I am using amazon-sp-api (JavaScript client for the Amazon Selling Partner API) but this is not limited to this client. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

八巷 2025-01-25 10:25:40

这方面的文档非常糟糕。不过,我已经通过相当多的尝试和错误成功地得到了其中的一些。

可以使用此 JSON 块设置履行和可用性

"fulfillment_availability": [{
"fulfillment_channel_code": "DEFAULT", 
"quantity": "9999", 
"lead_time_to_ship_max_days": "5"
}]

,并且奇怪的是,使用此块设置标价。不过,我仍在尝试找出如何设置含税标价。

"purchasable_offer": [{
"currency": "GBP",
"our_price": [{"schedule": [{"value_with_tax": 285.93}]}],
"marketplace_id": "A1F83G8C2ARO7P"
}]

希望这对您有帮助:)

The documentation for this side of things is terrible. I've managed to get some of it through a fair bit of trial and error though.

Fulfillment and Availability can be set with this block of JSON

"fulfillment_availability": [{
"fulfillment_channel_code": "DEFAULT", 
"quantity": "9999", 
"lead_time_to_ship_max_days": "5"
}]

and List price gets set, oddly, with this block. I'm still trying to find out how to set the List Price with Tax however.

"purchasable_offer": [{
"currency": "GBP",
"our_price": [{"schedule": [{"value_with_tax": 285.93}]}],
"marketplace_id": "A1F83G8C2ARO7P"
}]

Hope this helps you out :)

知足的幸福 2025-01-25 10:25:40

使用可以用它来更新价格和数量
注意 - 更改大约需要 20 分钟

{
    "productType": "PRODUCT",
      "patches": [
        {
          "op": "replace",
          "path": "/attributes/fulfillment_availability",
          "value": [
            {
              "fulfillment_channel_code": "DEFAULT",
              "quantity": 4
            }
          ]
        },
        {
            "op":
            "replace",
            "path":
            "/attributes/purchasable_offer",
            "value": [{
                "marketplace_id": "APJ6JRA9NG5V4",
                "currency": "EUR",
                "our_price": [{ "schedule": [{ "value_with_tax": 35.99 }] }]
            }]
        }
    ]
}

use can use this to update prices and quantity
Note -Changes will take around 20 min

{
    "productType": "PRODUCT",
      "patches": [
        {
          "op": "replace",
          "path": "/attributes/fulfillment_availability",
          "value": [
            {
              "fulfillment_channel_code": "DEFAULT",
              "quantity": 4
            }
          ]
        },
        {
            "op":
            "replace",
            "path":
            "/attributes/purchasable_offer",
            "value": [{
                "marketplace_id": "APJ6JRA9NG5V4",
                "currency": "EUR",
                "our_price": [{ "schedule": [{ "value_with_tax": 35.99 }] }]
            }]
        }
    ]
}
ゞ花落谁相伴 2025-01-25 10:25:40

那你尝试了补丁吗?

我可以使用此JSON:修补

{
    "productType":"BLANKET",
    "patches":[
    {
        "op":"replace",
        "path":"/attributes/fulfillment_availability",
        "value": [
            {
                "fulfillment_channel_code": "DEFAULT",
                "quantity": 33
            }
        ]
    }
  ]
}

端点上的产品数量:
{{host}}/listings/2021-08-01/items/:sellerId/:sku?marketPlaceIds = {{MarketPlaceId}}

have you tried patch then?

I could update product quantity with this json:

{
    "productType":"BLANKET",
    "patches":[
    {
        "op":"replace",
        "path":"/attributes/fulfillment_availability",
        "value": [
            {
                "fulfillment_channel_code": "DEFAULT",
                "quantity": 33
            }
        ]
    }
  ]
}

patching on the endpoint:
{{host}}/listings/2021-08-01/items/:sellerID/:sku?marketplaceIds={{marketplaceid}}

耳钉梦 2025-01-25 10:25:40

以下是我使用Salewever Spapi包装器的确切put_listings功能...希望JSON应该与您所做的事情相似。

@throttle_retry(tries = 10,延迟= 5,速率= 2.5)

def put_listings(new_sku,asin,asin,Lead_time,价格,价格,条件,AmazonMainProductType,类别,ISFBA,ISFBA,Shipphingname,shippingname,dentity,dentity,dentity,staightity,staightity,staightity,marketplace,moq = none,none,conditionNote = none,noteNote = none,** none,** none,** Kwargs):

recertentials = load_credentials()

# Prepare the body data for the API call
body_data = {
"productType": amazonMainProductType,
"requirements": "LISTING_OFFER_ONLY",
"sku": new_sku,
"summaries": [
    {
        "marketplaceId": marketplace,
        "asin": asin,
        "productType": category,
        "conditionType": condition,
        "status": ["DISCOVERABLE", "BUYABLE"],
        # "itemName": "Fortnite Series 2 Trading Card Fat Pack"
    }
],
"attributes": {
    "purchasable_offer": [
        {
            "our_price": [
                {
                    "schedule": [
                        {
                            "value_with_tax": price
                        }
                    ]
                }
            ],
            "marketplace_id": marketplace
        }
    ],
    "product_tax_code": [
        {
            "value": "A_GEN_TAX",
            "marketplace_id": marketplace
        }
    ],
    "merchant_suggested_asin": [
        {
            "value": asin,
            "marketplace_id": marketplace
        }
    ],
    "condition_type": [
        {
            "value": condition,
            "marketplace_id": marketplace
        }
    ],
    "merchant_shipping_group": [
        {
            "value": "legacy-template-id",
            "enumNames": shippingName,
            "marketplace_id": marketplace
        }
    ],
    "list_price": [
        {
            "value": price,
            "marketplace_id": "ATVPDKIKX0DER"
        }
    ],
    "fulfillment_availability": [
        {
            "fulfillment_channel_code": "DEFAULT",
            "quantity": quantity,
            "lead_time_to_ship_max_days": lead_time,
            "marketplace_id": marketplace
        }
    ]
},
"issues": [],
"offers": [
    {
        "marketplaceId": marketplace,
        "offerType": "B2C",
        "price": {
            "amount": price,
            "isFulfilledByAmazon": isFBA
                                    }
    }
],

"procurement": []

}

if moq is not None:
    body_data["attributes"]["max_order_quantity"] = [
        {
            "value": moq,
            "marketplace_id": marketplace
        }
    ]

if conditionNote:
    body_data["attributes"]["condition_note"] = [
        {
            "value": conditionNote,
            "marketplace_id": marketplace

        }
    ]

# If fulfillmentChannelCode indicates FBA (i.e., "AmazonNA"), 
    # we remove both the merchant_shipping_group and quantity from the attributes
if isFBA == "true":
    # Change fulfillment_channel_code to "AMAZON_NA"
    body_data["attributes"]["fulfillment_availability"][0] = {
        "fulfillment_channel_code": "AMAZON_NA",
        "marketplace_id": marketplace,
        "conditionType": condition,
        "isFulfilledByAmazon": isFBA
    }

    # Remove merchant_shipping_group
    if "merchant_shipping_group" in body_data["attributes"]:
        del body_data["attributes"]["merchant_shipping_group"]

    # Add batteries related information
    body_data["attributes"]["batteries_required"] = [
        {
            "value": False,  # Set to False as batteries are not required
            "marketplace_id": marketplace
        }
    ]

    # Set 'supplier_declared_dg_hz_regulation' to 'not_applicable'
    body_data["attributes"]["supplier_declared_dg_hz_regulation"] = [
        {
            "value": "not_applicable",
            "marketplace_id": marketplace
        }
    ]
else:
    # Keep fulfillment_channel_code as "DEFAULT" (or set it explicitly)
    body_data["attributes"]["fulfillment_availability"][0]["fulfillment_channel_code"] = "DEFAULT"
    # Set quantity based on the provided value
    body_data["attributes"]["fulfillment_availability"][0]["quantity"] = quantity


# dubugging line for api information #
# print(body_data) 
default_kwargs = {
    'marketplaceIds': marketplace,
    'sellerId': os.getenv("SELLER_ID"),
    'sku': new_sku,
    'body': body_data  # Pass the body data here
}

merged_kwargs = {**default_kwargs, **kwargs}

# dubugging line for api information #
# print("Sending the following data to put_listings_item:", merged_kwargs)

order_client = ListingsItems(credentials=credentials)
try:
    listing_items = order_client.put_listings_item(**merged_kwargs)
except Exception as e:
    print(f"Error: {e}")

# dubugging line for api information #
    # Print the full response
# print("Full API Response:")
# print(f"{listing_items}")

# Check the status of the response
status = listing_items.payload.get('status')
errors = listing_items.payload.get('errors')

if status == "ACCEPTED":
    print(f"{new_sku} - Listing Accepted at Amazon")
else:
    print(f"Error: {status}")
if errors == "NONE":
    print("No Errors")
else:
    print(f"Error: {errors}")
# print(listing_items)

return listing_items

Below is my exact put_listings function using the saleweaver spapi wrapper... hopefully the json should be similar to what you're doing regardless.

@throttle_retry(tries=10, delay=5, rate=2.5)

def put_listings(new_sku, asin, lead_time, price, condition, amazonMainProductType, category, isFBA, shippingName, quantity, marketplace, moq=None, conditionNote=None, **kwargs):

credentials = load_credentials()

# Prepare the body data for the API call
body_data = {
"productType": amazonMainProductType,
"requirements": "LISTING_OFFER_ONLY",
"sku": new_sku,
"summaries": [
    {
        "marketplaceId": marketplace,
        "asin": asin,
        "productType": category,
        "conditionType": condition,
        "status": ["DISCOVERABLE", "BUYABLE"],
        # "itemName": "Fortnite Series 2 Trading Card Fat Pack"
    }
],
"attributes": {
    "purchasable_offer": [
        {
            "our_price": [
                {
                    "schedule": [
                        {
                            "value_with_tax": price
                        }
                    ]
                }
            ],
            "marketplace_id": marketplace
        }
    ],
    "product_tax_code": [
        {
            "value": "A_GEN_TAX",
            "marketplace_id": marketplace
        }
    ],
    "merchant_suggested_asin": [
        {
            "value": asin,
            "marketplace_id": marketplace
        }
    ],
    "condition_type": [
        {
            "value": condition,
            "marketplace_id": marketplace
        }
    ],
    "merchant_shipping_group": [
        {
            "value": "legacy-template-id",
            "enumNames": shippingName,
            "marketplace_id": marketplace
        }
    ],
    "list_price": [
        {
            "value": price,
            "marketplace_id": "ATVPDKIKX0DER"
        }
    ],
    "fulfillment_availability": [
        {
            "fulfillment_channel_code": "DEFAULT",
            "quantity": quantity,
            "lead_time_to_ship_max_days": lead_time,
            "marketplace_id": marketplace
        }
    ]
},
"issues": [],
"offers": [
    {
        "marketplaceId": marketplace,
        "offerType": "B2C",
        "price": {
            "amount": price,
            "isFulfilledByAmazon": isFBA
                                    }
    }
],

"procurement": []

}

if moq is not None:
    body_data["attributes"]["max_order_quantity"] = [
        {
            "value": moq,
            "marketplace_id": marketplace
        }
    ]

if conditionNote:
    body_data["attributes"]["condition_note"] = [
        {
            "value": conditionNote,
            "marketplace_id": marketplace

        }
    ]

# If fulfillmentChannelCode indicates FBA (i.e., "AmazonNA"), 
    # we remove both the merchant_shipping_group and quantity from the attributes
if isFBA == "true":
    # Change fulfillment_channel_code to "AMAZON_NA"
    body_data["attributes"]["fulfillment_availability"][0] = {
        "fulfillment_channel_code": "AMAZON_NA",
        "marketplace_id": marketplace,
        "conditionType": condition,
        "isFulfilledByAmazon": isFBA
    }

    # Remove merchant_shipping_group
    if "merchant_shipping_group" in body_data["attributes"]:
        del body_data["attributes"]["merchant_shipping_group"]

    # Add batteries related information
    body_data["attributes"]["batteries_required"] = [
        {
            "value": False,  # Set to False as batteries are not required
            "marketplace_id": marketplace
        }
    ]

    # Set 'supplier_declared_dg_hz_regulation' to 'not_applicable'
    body_data["attributes"]["supplier_declared_dg_hz_regulation"] = [
        {
            "value": "not_applicable",
            "marketplace_id": marketplace
        }
    ]
else:
    # Keep fulfillment_channel_code as "DEFAULT" (or set it explicitly)
    body_data["attributes"]["fulfillment_availability"][0]["fulfillment_channel_code"] = "DEFAULT"
    # Set quantity based on the provided value
    body_data["attributes"]["fulfillment_availability"][0]["quantity"] = quantity


# dubugging line for api information #
# print(body_data) 
default_kwargs = {
    'marketplaceIds': marketplace,
    'sellerId': os.getenv("SELLER_ID"),
    'sku': new_sku,
    'body': body_data  # Pass the body data here
}

merged_kwargs = {**default_kwargs, **kwargs}

# dubugging line for api information #
# print("Sending the following data to put_listings_item:", merged_kwargs)

order_client = ListingsItems(credentials=credentials)
try:
    listing_items = order_client.put_listings_item(**merged_kwargs)
except Exception as e:
    print(f"Error: {e}")

# dubugging line for api information #
    # Print the full response
# print("Full API Response:")
# print(f"{listing_items}")

# Check the status of the response
status = listing_items.payload.get('status')
errors = listing_items.payload.get('errors')

if status == "ACCEPTED":
    print(f"{new_sku} - Listing Accepted at Amazon")
else:
    print(f"Error: {status}")
if errors == "NONE":
    print("No Errors")
else:
    print(f"Error: {errors}")
# print(listing_items)

return listing_items
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文