Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-200 response with spending_catgories payload #3

Open
kotliary opened this issue Jun 12, 2024 · 1 comment
Open

non-200 response with spending_catgories payload #3

kotliary opened this issue Jun 12, 2024 · 1 comment

Comments

@kotliary
Copy link

kotliary commented Jun 12, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants