02-16-2023 11:16 AM
hello Everyone, new to APIs and working on something for a personal usecase. can someone help me with the code that I have generated to bring back all the luxury watches on Ebay. i am getting item_DF and other items as null when trying to fetch data. any help is highly appreciated.
library(httr)
library(jsonlite)
query <- "rolex|breitling|cartier|omega|Audemars Piguet|Patek Philippe|panerai|hublot"
url <- paste0("https://api.ebay.com/buy/browse/v1/item_summary/search?q=", URLencode(query), "&filter=listingFormat:{fixed_price}+condition:{new}+priceCurrency:{USD}&limit=10")
response <- GET(url,
add_headers(Authorization = "Bearer <I used my token here>",
"Content-Type" = "application/json",
"X-EBAY-C-MARKETPLACE-ID" = "EBAY",
"X-EBAY-C-ENDUSERCTX" = "contextualLocation=country=US"))
items <- content(response)$itemSummaries
item_data <- lapply(items, function(x) {
data.frame(brand = x$brand, model = x$title, condition = x$condition, location = x$location, price = x$price$value, currency = x$price$currency)
})
item_df <- do.call(rbind, item_data)
02-16-2023 04:54 PM
I don' recognize your library, and don't use the Browse API, so only marginal help here.
But hopefully, some of this will get you a little closer to your goal.
Reading through the Browse API options, these pages might help:
https://developer.ebay.com/api-docs/buy/browse/resources/methods
https://developer.ebay.com/api-docs/buy/static/ref-buy-browse-filters.html
Without a category, you'll get parts, ephemera, and unrelated items.
This is a visual representation of the query for your endpoint (you'll need to correctly encode it):
?q=URLencode( (rolex,breitling,cartier,omega,Audemars Piguet,Patek Philippe,panerai,hublot) )
&category_ids=31387
&filter=URLencode(listingFormat:FIXED_PRICE,conditions:NEW,priceCurrency:USD)
&limit=10
optional aspect
&aspect_filter=URLencode(categoryId:31387,Brand:{rolex|breitling|cartier|omega|Audemars Piguet|Patek Philippe|panerai|hublot})
"X-EBAY-C-MARKETPLACE-ID" = "EBAY" "EBAY_US"
"X-EBAY-C-ENDUSERCTX" = "contextualLocation=URLencode(country=US)"