How to use Amazon Product Advertising API in C# .net Core?
Amazon Product Advertising API is an API using which users can integrate search feature and show products from Amazon. Some days ago I wanted to integrate this API into my app. I went through Amazon’s PA-API documentation and I came to know that Amazon had not written code to consume this API in C#. If you are also facing the same issue then this article is for you. Let’s see how I have integrated Amazon PA-API in .net core?
Product Advertising API(PA API) implementation
Install the below package through Package Manager Console (You can search it in Nuget explorer also)
Install-Package Nager.AmazonProductAdvertising
You can search for Amazon products using PA API in 4 ways:
- Item Search (simple)
- Item Search (advanced)
- Item Lookup
- Multi-Item Lookup
1. Item Search (simple)
var authentication = new AmazonAuthentication("Your Access Key", "Your Secret Key");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.IN, "salman-21");
var result = await client.SearchItemsAsync("samsung tv");
- To get your Access Key and Secret Key click this 👉 link
- In the third line of code, you can see the search keyword “samsung tv”. Using this keyword Amazon will return product details of Samsung Tv’s
2. Item Search (advanced)
var authentication = new AmazonAuthentication("Your Access Key", "Your Secret Key");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.IN, "salman-21");
var searchRequest = new SearchRequest
{
Keywords = "samsung tv",
ItemPage = 1,
Resources = new []
{
"Images.Primary.Large",
"ItemInfo.Title",
"ItemInfo.Features",
"Offers.Listings.Price",
}
};
var result = await client.SearchItemsAsync(searchRequest);
- Using advance search we can get the desired result which we want. On a single call to API, you will receive 10 product details if you want more products then make another separate call to API with 2, 3, 4, etc as ItemPage value.
- You can found all available Resources in the documentation 👉 link
3. Item Lookup
var authentication = new AmazonAuthentication("Your Access Key", "Your Secret Key");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.IN, "salman-21");
var result = await client.GetItemsAsync("B00BYPW00I");
- Along with words if an user wants to search specific products using ASIN then you can use the above code.
4. Multi-Item Lookup
var authentication = new AmazonAuthentication("Your Access Key", "Your Secret Key");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.IN, "salman-21");
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });
- For getting multiple specific items, you can pass multiple ASIN(B00BYPW00I) string like the above code.
Note: Please check the AmazonEndpoint is correct for your Country.
- Amazon India use AmazonEndpoint.IN
- Amazon Spain use AmazonEndpoint.ES
- Amazon United Kingdom use AmazonEndpoint.UK
Official Package Repository: https://github.com/nager/Nager.AmazonProductAdvertising
Official Amazon Documentation: https://webservices.amazon.com/paapi5/documentation/
If you like this article then please clap it. Your clap matters a lot ❤️ to me.