Search code examples
rodatahttr

passing odata $filter in httr GET request


looking to pass $filter criteria using odata in R's httr package, but keep getting an 'Error 400. The request is badly formed'.

I'm able to paste the url/$filter in my browser and obtain results ok, and am also to obtain results in R without the $filter. It's just using the $filter option in R that I'm getting the error:

library(httr)
url <- "https://api.prosper.com/api/ListingsHistorical?$filter=year(ListingCreationDate) eq 2014"
response <- GET(url, authenticate('user', 'pass')

Above, in R, is what's throwing the 400 response. In browser works fine.


Solution

  • Figured it out. I needed to include %20 for the spaces when declaring the url variable.

    Working:

    library(httr)
    url <- "https://api.prosper.com/api/ListingsHistorical?$filter=year(ListingCreationDate)%20eq%202014"
    response <- GET(url, authenticate('user', 'pass')