Amazon SP-API - submit listings item patch request

henryvuong

Member
Joined
Sep 8, 2023
Messages
15
Programming Experience
3-5
I am using C# code to make API call to Amazon SP-API. I have read though these documents:

Automate your SP-API calls using C# SDK

Listings Items API v2021-08-01 Use Case Guide

I have successfully submitted listings GET request, but not sure how to submit PATCH request. I am trying to change the price of an item. Below is my code. The "body" parameter is where I got stuck. I am not sure If I do it right. Please advise.

C#:
public static void Main()
{
    try
    {
        LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials
        {
            ClientId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            RefreshToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            Endpoint = new Uri("https://api.amazon.com/auth/o2/token")
        };

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

        string sellerId = "XXXXXXXXXXX";
        List<string> marketplaceIds = new List<string>();
        marketplaceIds.Add("ATVPDKIKX0DER");
        string sku = "XXX-YYY-ZZZ";
        
//*** This is the part where I got error
//*** I am not sure if I am doing correctly
ListingsItemPatchRequest body = new ListingsItemPatchRequest();
        body =  {
            "productType":"CELLULAR_PHONE",
              "patches":[

                {
                "op":"replace",
                  "path":"/attributes/purchasable_offer",
                  "value":[
                    {
                    "marketplace_id": "ATVPDKIKX0DER",
                      "currency": "USD",
                      "our_price": [
                        {
                        "schedule": [
                                              {
                            "value_with_tax": 15.00
                                              }
                          ]
                        }
                      ]
                    }
                  ]
                }

              ]
            }

        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);
    }
}
 
What error are you getting?
 
Lines 25-50 doesn't look like valid C# to me.

If you wanted to put in raw JSON there, you'll need to use the raw string literals feature:

But I still have doubts whether that ListingsItemPatchRequest class supports take a literal JSON string to initialize the class members. It's more likely that you'll need to initialize each of the members of the class one at a time, or some kind of DOM-like manner (ala WPF and XML-DOM C# classes).
 
Last edited:
I have modified my code and repost the question with some clarification under a new thread. Here;'s the link, please view and give advise. Thanks

 

Latest posts

Back
Top Bottom