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
580 stars 730 forks source link

How to update the inventory quantity of a single product ? #417

Closed harili closed 3 months ago

harili commented 2 years ago

Hello,

After 2 hours of searching on the API Documentation, I didn't find the endpoind that allowed me to update the inventory quantity of a product.

If someone have a track, I'm here !

harili commented 2 years ago

Here a little track : https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2021-08-01-use-case-guide Still waiting for suggestions

rugved1991 commented 2 years ago

Hi @harili,

You can use the Feeds API to update the inventory. Please review the feed type "POST_INVENTORY_AVAILABILITY_DATA" for more information. https://developer-docs.amazon.com/sp-api/docs/feed-type-values#listings-feeds

You can also use Listings API to update listing information: https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2021-08-01-use-case-guide#tutorial-partially-update-a-listing

Rugved Solutions Architect, SP API

harili commented 2 years ago

Hi @harili,

You can use the Feeds API to update the inventory. Please review the feed type "POST_INVENTORY_AVAILABILITY_DATA" for more information. https://developer-docs.amazon.com/sp-api/docs/feed-type-values#listings-feeds

You can also use Listings API to update listing information: https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2021-08-01-use-case-guide#tutorial-partially-update-a-listing

Rugved Solutions Architect, SP API

Hello @rugved1991 ! Can't I use this following tutorial to update the inventory NOR create a product ? src: https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2021-08-01-use-case-guide#tutorial-create-or-fully-update-a-listing

Is there a difference between those two links (the ones you gave to me) ?

As you said, I can use Feeds API, and use a specific type, but isn't more difficult ? I'm sorry, it is my first time with SP API. Thanks !

bpyzikvc commented 2 years ago

@harili Those two links are talking about two different endpoints. One is a PUT which will create or do a full update while the other is a PATCH in which you can update a specific field.

To update inventory, I would suggest using the PATCH and updating the fulfillment_availability (the attribute for inventory updates). You can refer to the Product Type Definitions API for the schema describing the structure of the attributes and then use the PATCH to update them separately from updating an entire listing.

Unless you are forced to use Feeds for something else already, I would avoid it if you can because of its complexity.

mzbk commented 2 years ago

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

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
                }
            ]
        }
    ]
}
muzammilodesk commented 1 year ago

Is it possible to update the inventory quantity of multiple products through Api?

mzbk commented 1 year ago

Is it possible to update the inventory quantity of multiple products through Api?

Yes, loop on the body or you can use the feed process.

talhakhadim commented 1 year ago

is there a way to find seller Id through sp api ? if yes kindly mention the endpoint..

mzbk commented 1 year ago

is there a way to find the seller Id through sp API? if yes kindly mention the endpoint..

The seller ID is in your store URL Click on your store on Amazon and check the URL you will see the seller ID.

https://www.amazon.co.jp/s?me=**A38GB1HVG3KV8Z**&language=en&marketplaceID=**A1VC38T7YXB528**

Amazon sp API provides https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations to retrieve seller detail with this API. I don't know if we get the seller ID or not.

talhakhadim commented 1 year ago

is there a way to find the seller Id through sp API? if yes kindly mention the endpoint..

The seller ID is in your store URL Click on your store on Amazon and check the URL you will see the seller ID.

https://www.amazon.co.jp/s?me=**A38GB1HVG3KV8Z**&language=en&marketplaceID=**A1VC38T7YXB528**

Amazon sp API provides https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations to retrieve seller detail with this API. I don't know if we get the seller ID or not.

Thanks for the response, but "getmarketplaceparticipations" response did not contain seller Id, Actually i want to update inventory but it requires seller Id (different sellers) so i can't get that from the above mentioned url.

mzbk commented 1 year ago

is there a way to find the seller Id through sp API? if yes kindly mention the endpoint..

The seller ID is in your store URL Click on your store on Amazon and check the URL you will see the seller ID. https://www.amazon.co.jp/s?me=**A38GB1HVG3KV8Z**&language=en&marketplaceID=**A1VC38T7YXB528 Amazon sp API provides https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations** to retrieve seller detail with this API. I don't know if we get the seller ID or not.

Thanks for the response, but "getmarketplaceparticipations" response did not contain seller Id, Actually i want to update inventory but it requires seller Id (different sellers) so i can't get that from the above mentioned url.

Do you know the stores? open each store and get the seller id from backend or from URL.

talhakhadim commented 1 year ago

is there a way to find the seller Id through sp API? if yes kindly mention the endpoint..

The seller ID is in your store URL Click on your store on Amazon and check the URL you will see the seller ID. https://www.amazon.co.jp/s?me=**A38GB1HVG3KV8Z**&language=en&marketplaceID=**A1VC38T7YXB528 Amazon sp API provides https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations** to retrieve seller detail with this API. I don't know if we get the seller ID or not.

Thanks for the response, but "getmarketplaceparticipations" response did not contain seller Id, Actually i want to update inventory but it requires seller Id (different sellers) so i can't get that from the above mentioned url.

Do you know the stores? open each store and get the seller id from backend or from URL. Actually I hav access token of every store in our application which we save after authenticate them, so no URL option, I just want some api endpoint where i can get seller id and save it, Any other option to update inventory of an sku (without the need of seller Id)?

SafeerAhmFarooqi commented 1 year ago

When the seller approves the consent and your redirect URI is hit by amazon seller id is provided in that request. I use to save that seller id in my DB for later use.

jpmangoit commented 1 year ago

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

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

While updating the inventory, I am getting the ACCEPTED staus and the submissionId with no issues in the response, But the product's inventory is not updated at all. Can you please tell me where the issue can be ?

oof2win2 commented 1 year ago

While updating the inventory, I am getting the ACCEPTED staus and the submissionId with no issues in the response, But the product's inventory is not updated at all. Can you please tell me where the issue can be ?

I'm having the same issue, but this is with all of my feeds overall. Can't create or remove product listings with feeds, but it's working with the API for individual products.

Alicg commented 1 year ago

While updating the inventory, I am getting the ACCEPTED staus and the submissionId with no issues in the response, But the product's inventory is not updated at all. Can you please tell me where the issue can be ?

I'm having the same issue, but this is with all of my feeds overall. Can't create or remove product listings with feeds, but it's working with the API for individual products.

@oof2win2 how do you update products' quantity with the API other than feeds API? Neither way works for me.

oof2win2 commented 1 year ago

@oof2win2 how do you update products' quantity with the API other than feeds API? Neither way works for me.

I haven't gotten around to migrating to SP for product stocks, I'm still using MWS for that.

wish-master commented 11 months ago

While updating the inventory, I am getting the ACCEPTED staus and the submissionId with no issues in the response, But the product's inventory is not updated at all. Can you please tell me where the issue can be ?

For me @mzbk approach works quite fine. I had the same issue, like @jpmangoit mentioned, but it was resolved itself in a while, we just need to wait a little bit.

henryvuong2 commented 7 months ago

I am using my C# SDK to make API calls, as instructed in this document: https://developer-docs.amazon.com/sp-api-blog/docs/automate-your-sp-api-calls-using-the-c-sdk

The model I am using is listings-items-api-model. I am trying to submit listings item patch request to change the inventory quantity of a listing. Here is the code I inserted into ListingApiTests class for testing:

`public static void Main()

{ try { LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials { ClientId = "XXXXXXXXXXXX", ClientSecret = "XXXXXXXXXXXX", RefreshToken = "XXXXXXXXXXXX", Endpoint = new Uri("https://api.amazon.com/auth/o2/token") };

    ListingsApi listingsApi = new ListingsApi.Builder()
        .SetLWAAuthorizationCredentials(lwaAuthorizationCredentials)
        .Build();

    string sellerId = "XXXXXXXXXXXX";
    List<string> marketplaceIds = new List<string>();
    marketplaceIds.Add("ATVPDKIKX0DER");

    //Patch Listing request
    string sku = "XXX-YYY-ZZZ";

    string body = @"
        {
            'productType': 'CELLULAR_PHONE',
            'patches': [
                {
                    'op': 'replace',
                    'operation_type': 'PARTIAL_UPDATE',
                    'path': '/attributes/fulfillment_availability',
                    'value': [
                        {
                            'fulfillment_channel_code': 'DEFAULT',
                            'quantity': 1
                        }
                    ]
                }
            ]
        }";

    ListingsItemSubmissionResponse result = listingsApi.PatchListingsItem(sellerId, sku, marketplaceIds, body);

    Console.WriteLine(result.ToJson());
    Console.ReadLine();
}
catch (LWAException e)
{
    Console.WriteLine("LWA Exception when calling SellersApi#getMarketplaceParticipations");
    Console.WriteLine(e.getErrorCode());
    Console.WriteLine(e.getErrorMessage());
    Console.WriteLine(e.Message);
}
catch (ApiException e)
{
    Console.WriteLine("Exception when calling SellersApi#getMarketplaceParticipations");
    Console.WriteLine(e.Message);
}

}`

The error I got is:

Error CS1503 Argument 4: cannot convert from 'string' to 'SellingPartnerAPI.ListingsItemsAPI.Model.ListingsItemPatchRequest'

This error comes from the listingsApi.PatchListingsItem method. Obviously, I need to convert 'body' to something before I can use it as an argument in this method. Please advise.