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.
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);
}
}