Issue with non-query parameters in GET vs POST requests
Hi all,
There is a behaviour with my requests that I am struggling to understand, but I was hoping someone could help me figure it out. I apologise in advance if this is a coding error rather than something more related to the API.
Essentially, I receive the expected response when I submit my request using the GET method. However, when I use the same parameters with POST, the response ignores everything but the query.
I have an example in R with a request using query and options.
library(purrr)
library(httr2)
library(dplyr)
library(jsonlite)
params <- list(
q = list("_gte" = list(patent_date = "2024-01-01")),
o = list(size = 30)
)
req <- request("https://search.patentsview.org/api/v1/patent") |>
req_headers("X-Api-Key" = api_key) |>
req_throttle(45 / 60)
req_get <- req |>
req_url_query(
q = toJSON(params$q, auto_unbox = TRUE),
o = toJSON(params$o, auto_unbox = TRUE)
)
resp_get <- req_get |>
req_perform() |>
resp_body_json() |>
pluck("patents") |>
bind_rows() # returns 30 observations in the correct date range
req_post <- req |>
req_body_json(params)
resp_post <- req_post |>
req_perform() |>
resp_body_json() |>
pluck("patents") |>
bind_rows() # returns 100 observations in the correct date range