bikeactuary / repoRter.nih

R Interface to the National Institute of Health's (NIH) Reporter API v2
Other
4 stars 1 forks source link

non-200 response with spending_catgories payload #3

Open kotliary opened 3 weeks ago

kotliary commented 3 weeks ago

Request with spending_categories payload returns non-200 error.

Comparing the JSON code with API doc I found that true or false in match_all should not be inside square brackets. Removing them makes the code work.

library(repoRter.nih)
req <- make_req(criteria =
                  list(fiscal_years = 2010,
                       spending_categories = list(values = c(873, 180), match_all = T)) 
)
#> This is your JSON payload:
#> {
#>     "criteria": {
#>         "fiscal_years": [
#>             2010
#>         ],
#>         "spending_categories": {
#>             "values": [
#>                 873,
#>                 180
#>             ],
#>             "match_all": [
#>                 true
#>             ]
#>         },
#>         "use_relevance": false,
#>         "include_active_projects": false,
#>         "exclude_subprojects": false,
#>         "multi_pi_only": false,
#>         "newly_added_projects_only": false,
#>         "sub_project_only": false
#>     },
#>     "offset": 0,
#>     "limit": 500
#> }
#> 
#> If you receive a non-200 API response, compare this formatting (boxes, braces, quotes, etc.) to the 'Complete Payload' schema provided here:
#> https://api.reporter.nih.gov/?urls.primaryName=V2.0#/Search/post_v2_projects_search
res <- get_nih_data(req)
#> Retrieving first page of results (up to 500 records)
#> Request failed [400]. Retrying in 1 seconds...
#> Request failed [400]. Retrying in 2.6 seconds...
#> API Error: received non-200 response - please try again later and if the issue persists
#>             report the issue to the package maintainer (include the request JSON which is failing).

# Remove square brackets around true or false
req = structure(stringr::str_replace(req, "\\[((true)|(false))\\]", "\\1"), class = "json")
res <- get_nih_data(req)
#> Retrieving first page of results (up to 500 records)

Created on 2024-06-12 with reprex v2.0.2

bikeactuary commented 3 weeks ago

Thank you @kotliary - not able to update the CRAN release until next week but will uodate the dev version soon or feel free to edit and issue a PR