@@ -504,6 +504,54 @@ but the build will silently fail on r-universe. Don't ask how I know that.
504
504
there isn't the 100,000 row limitation now. The API's ```after``` is now exposed
505
505
in search_pv() so users could do their own paging. See the new [paging vignette](result-set-paging.html)
506
506
507
+ ## Odd Demo
508
+ Here we demonstrate a weird interaction between the API and R package when no sort parmeter
509
+ is specified.
510
+
511
+ ```{r}
512
+ fields <- c("patent_id", "patent_date", "patent_title")
513
+
514
+ search_pv(
515
+ query = '{"_gte":{"patent_date":"2007-01-01"}}',
516
+ endpoint = "patent", fields = fields
517
+ )
518
+ ```
519
+
520
+ Note that the first patent_date returned above is "2020-04-21" and that what gets
521
+ sent to the API is ` &s=[]&o= `
522
+
523
+ ``` {r}
524
+ url <- httr2::last_request()$url
525
+ cat(utils::URLdecode(url))
526
+ ```
527
+
528
+
529
+ Now we'll send in our own GET with ` &s=&o ` to see that the API return is different,
530
+ seemingly applying a default sort?
531
+
532
+ ``` {r}
533
+ library(httr2)
534
+
535
+ url <- sub("&s=\\[\\]", "&s=", url)
536
+ cat(utils::URLdecode(url))
537
+ api_key <- Sys.getenv("PATENTSVIEW_API_KEY")
538
+
539
+ req <- httr2::request(url) |>
540
+ httr2::req_method("GET")
541
+
542
+ resp <- req |>
543
+ httr2::req_user_agent("https://github.com/ropensci/patentsview") |>
544
+ httr2::req_retry(max_tries = 20) |> # automatic 429 Retry-After
545
+ httr2::req_headers("X-Api-Key" = api_key, .redact = "X-Api-Key") |>
546
+ httr2::req_perform()
547
+
548
+ json <- httr2::last_response() |> httr2::resp_body_json()
549
+ json$patents[[1]]
550
+
551
+ ```
552
+ For a while POSTs and GETs behaved differently when a sort wasn't specified. Currently
553
+ an API bug prevents seeing what the behavior is on POSTS.
554
+
507
555
[ ^ 1 ] : Observation sent to the API team.
508
556
[ ^ 2 ] : Observation sent to the API team.
509
557
[ ^ 3 ] : There isn't a data dictionary for the API so I suggested they create one.
0 commit comments