Skip to main content
 
 
 
IN THIS SECTION
5 posts
gabriellobo
Last seen: 01/26/2025 - 15:58
Joined: 01/21/2025 - 08:38
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
gabriellobo
Last seen: 01/26/2025 - 15:58
Joined: 01/21/2025 - 08:38
Fix

I figured out the problem in case anyone has the same issue. If you are using POST it will only work as expected if you specify all the parameters.

Russ
Last seen: 01/27/2025 - 16:13
Joined: 11/14/2017 - 22:15
there is an R package

Hi gabriellobo,

We're working through a PR to update the R package for the new version of the API, what's on CRAN works with the original version of the API.  If you are interested, you could install a beta version from r-universe as explained in my fork.  You'd need to put the value of your API key in an environmental variable PATENTSVIEW_API_KEY.  There are updated vignettes too to guide you.   

I think the API team plans on shutting down the original version of the API in about three weeks. We'll submit the updated package to CRAN at that point.

Russ Allen

 

gabriellobo
Last seen: 01/26/2025 - 15:58
Joined: 01/21/2025 - 08:38
Dear Russ,Thank you very…

Dear Russ,

Thank you very much! I will try it out.

PVTeam
Role: moderator
Last seen: 01/27/2025 - 16:20
Joined: 10/17/2017 - 10:47
Legacy API retirement and Search API bug fix

Hi gabriellobo,

Thank you for posting your question and solution. Russ is correct that PatentsView is scheduled to retire our Legacy API (aka original version) on Feb 12th, 2025. A fix for the bug that prevents the API from properly parsing all POST parameters when some are omitted will be included in our next Search API update, which we expect to come around the same time the Legacy API is retired.

Please let us know if you have any questions or concerns.

Best,
PVTeam