Ebay Browse API
Hi I'm creating an application for myself to help with my ebay bussiness. my goal is to import a spreadsheet of part numbers ( these part numbers are for electronic components ) into a datagridvidew ( this is a vb.net application ) and use the browse or search api to go thru all the part numbers, encode the part number as a string and pass it into a search query to pull back information on listings of how many items sold, min price, max price, and some other info. here is the api call I'm using ( https://api.ebay.com/buy/browse/v1/item_summary/search ) here is the query and response code (
Dim limit As Integer = 50
Dim offset As Integer = 0
Dim maxResults As Integer = 1000
While offset < maxResults
For Each kvp In partNumbers
Dim partNumber As String = kvp.Key
Dim encodedPartNumber As String = Uri.EscapeDataString(partNumber)
Dim query As String = $"{apiUrl}?q={encodedPartNumber}+OR+{encodedPartNumber}+AND+title:{encodedPartNumber}&fieldgroups=ASPECTS&limit={limit}&offset={offset}&sort=BestMatch"
Dim response As HttpResponseMessage = Await client.GetAsync($"{apiUrl}?q={encodedPartNumber}+AND+title:{encodedPartNumber}&fieldgroups=ASPECTS&limit=10&sort=BestMatch") , when i run my application with this part number ( M27C512-15F1 ) i get this message ( No item summaries found for part number M27C512-15f1 ) but i know this part number exists on ebay because i have a listing for this part number myself. Here is the code that declares the query and response and proccesses it all if susccessful (
For Each kvp In partNumbers
Dim partNumber As String = kvp.Key
Dim encodedPartNumber As String = Uri.EscapeDataString(partNumber)
Dim query As String = $"{apiUrl}?q={encodedPartNumber}+OR+{encodedPartNumber}+AND+title:{encodedPartNumber}&fieldgroups=ASPECTS&limit={limit}&offset={offset}&sort=BestMatch"
Dim response As HttpResponseMessage = Await client.GetAsync($"{apiUrl}?q={encodedPartNumber}+AND+title:{encodedPartNumber}&fieldgroups=ASPECTS&limit=10&sort=BestMatch")
Try
If response.IsSuccessStatusCode Then
Dim content As String = Await response.Content.ReadAsStringAsync()
Dim json As JObject = JObject.Parse(content)
' Process the API response, extract and calculate the required data
Dim items As JArray = json("itemSummaries")
If items IsNot Nothing Then
Dim lowPrice As Double = Double.MaxValue
Dim highPrice As Double = Double.MinValue
Dim totalPrices As Double = 0
Dim count As Integer = 0
Dim sellRate As Double = 0
Dim listingsSold As Integer = 0
For Each item As JObject In items
Dim priceToken = item("price")?("value")
Dim price As Double = If(priceToken IsNot Nothing, priceToken.ToObject(Of Double)(), 0)
lowPrice = Math.Min(lowPrice, price)
highPrice = Math.Max(highPrice, price)
totalPrices += price
count += 1
Dim buyingOptions = item("buyingOptions")
If buyingOptions IsNot Nothing Then
sellRate += buyingOptions.Count(Function(buyingOption) buyingOption.ToString() = "FIXED_PRICE")
End If
Dim soldQuantityToken = item("sellingStatus")?("soldQuantity")
If soldQuantityToken IsNot Nothing Then
listingsSold += soldQuantityToken.ToObject(Of Integer)()
End If
Next
Dim avgPrice As Double = If(count > 0, totalPrices / count, 0)
Dim searchActivity As Integer = items.Count
Dim result As New Dictionary(Of String, String) From {
{"PartNumber", partNumber},
{"LowPrice", If(lowPrice = Double.MaxValue, "N/A", lowPrice.ToString())},
{"HighPrice", If(highPrice = Double.MinValue, "N/A", highPrice.ToString())},
{"AveragePrice", avgPrice.ToString()},
{"SearchActivity", searchActivity.ToString()},
{"SellRate", sellRate.ToString()},
{"ListingsSold", listingsSold.ToString()},
{"SearchKeywords", partNumber}
}
results.Add(result)
Else
Console.WriteLine($"No item summaries found for part number {partNumber}")
End If
Else
Console.WriteLine($"Error: {response.StatusCode}")
End If
Catch ex As Exception
Console.WriteLine($"Error processing part number {partNumber}: {ex.Message}")
End Try
Next
offset += limit
End While
Return results ) if anyone can please help me with this, it would be greatly appreciated