httr2
httr2 copied to clipboard
Support for array query parameters
Hello This is not a bug report.
I am working with the Taxonworks API the biological_association endpoint https://api.taxonworks.org/#/biological_associations-get that requires integer arrays I give an example:
req_bioass_sandfly_query = req_bioass_sandfly %>%
req_url_query(
list("object_taxon_name_id[]"=474243),
list("biological_relationship_id[]"=12))
and also
req_bioass_sandfly_query = req_bioass_sandfly %>%
req_url_query(
"object_taxon_name_id[]"=474243,
"biological_relationship_id[]"=12)
but it doesn't work. Can someone help me?
Here
#Define query req_bioass_sandfly_query = req_bioass_sandfly %>% req_url_query( "subject_taxon_name_id[]"=474243) %>% req_url_query( "biological_relationship_id[]"=13) %>% req_url_query( taxon_name_id_mode="true")
so "...[]"=int is true but the taxonworks reduired other query parameter.
Excuse-me
But for taxonworks is possible to add the same query with different value For example https://sandfly.taxonworks.org/biological_associations/filter.json?subject_taxon_name_id%5B%5D=474243&taxon_name_id_mode=true&biological_relationship_id%5B%5D=13&biological_relationship_id%5B%5D=11&biological_relationship_id%5B%5D=10&extend%5B%5D=object&extend%5B%5D=subject&extend%5B%5D=biological_relationship&extend%5B%5D=taxonomy&extend%5B%5D=biological_relationship_types I tried with
#Define query
req_bioass_sandfly_query = req_bioass_sandfly %>%
req_url_query(
"subject_taxon_name_id[]"=474243) %>%
req_url_query(
"biological_relationship_id[]"=8) %>%
req_url_query(
"biological_relationship_id[]"=12) %>%
req_url_query(
"biological_relationship_id[]"=13) %>%
req_url_query(
"biological_relationship_id[]"=14) %>%
req_url_query(
taxon_name_id_mode="true")
but the result was https://sandfly.taxonworks.org/api/v1/biological_associations?project_token=mVY5aWD-vLsfAxDGQeWaJA&subject_taxon_name_id%5B%5D=474243&biological_relationship_id%5B%5D=14&taxon_name_id_mode=true so only the last query was taken
Excuse-me:
#Define query
req_bioass_sandfly_query = req_bioass_sandfly %>%
req_url_query(
"subject_taxon_name_id[]"=474243) %>%
req_url_query(
"biological_relationship_id[]"=8,
"biological_relationship_id[]"=12,
"biological_relationship_id[]"=13,
"biological_relationship_id[]"=14,
"biological_relationship_id[]"=10) %>%
req_url_query(
taxon_name_id_mode="true")
This is a relatively common need so it might be nice if we had some syntax for it, e.g.:
req_bioass_sandfly_query <- req_bioass_sandfly %>%
req_url_query(
"subject_taxon_name_id[]" = 474243,
biological_relationship_id = c(8, 12, 13, 14, 10),
taxon_name_id_mode = "true"
.multi = "array"
)
Or maybe
# Define query
req_bioass_sandfly_query <- req_bioass_sandfly %>%
req_url_query(
"subject_taxon_name_id[]" = 474243,
"biological_relationship_id[]" = c(8, 12, 13, 14, 10),
taxon_name_id_mode = "true"
.multi = "repeat"
)
Hi. the two possibilities done the same error:
Error in
query_build()
: ! Query parameters must be length 1 atomic vectors. • Problems: biological_relationship_id[]
Those were proposals for things that might work in the future, not code that works today.