The function doQueryApi is called by all the function querying the API endpoints and return the raw data sent by the endpoint.

doApiQuery(api, endpoint, ..., params)

Arguments

api

a character name of the API (e.g.: "indicateurs_services", "prelevements"...), see example for available APIs

endpoint

a character name of the endpoint, see example for available endpoints in an API

...

parameters of the queries and their values in the format Param1_Name = "Param1 value", Param2_Name = "Param2 value", use the function list_params for a list of the available filter parameters for a given API endpoint and see the API documentation for their description

params

(deprecated) a list the list of parameters of the queries and their values in the format list(ParamName = "Param value", ...). This parameter is replaced by the parameter ...

Value

A list with the concatenated results returned by the API.

Details

Pagination of the queries is handled automatically and the returned list is the concatenation of all the results sent by the API.

The functions get_[api]_[endpoint] call the function doQueryApi and parse the response in a tibble::tibble format for the user (See convert_list_to_tibble).

By default the user agent used for the query is "https://github.com/inrae/hubeau". You can redefined the user agent with the global option "hubeau.user_agent": options(hubeau.user_agent = "My user agent").

Examples

# To get the available APIs in the package
list_apis()
#>  [1] "prelevements"         "indicateurs_services" "hydrometrie"         
#>  [4] "niveaux_nappes"       "poisson"              "ecoulement"          
#>  [7] "hydrobio"             "temperature"          "qualite_eau_potable" 
#> [10] "qualite_nappes"       "qualite_rivieres"    

# To get the available endpoints in an API
list_endpoints("prelevements")
#> [1] "chroniques"         "ouvrages"           "points_prelevement"

# To get available parameters in endpoint "chroniques" of the API "prelevements"
list_params(api = "prelevements", endpoint = "chroniques")
#>  [1] "annee"                      "bbox"                      
#>  [3] "code_commune_insee"         "code_departement"          
#>  [5] "code_mode_obtention_volume" "code_ouvrage"              
#>  [7] "code_qualification_volume"  "code_statut_instruction"   
#>  [9] "code_statut_volume"         "code_usage"                
#> [11] "distance"                   "fields"                    
#> [13] "format"                     "latitude"                  
#> [15] "libelle_departement"        "longitude"                 
#> [17] "nom_commune"                "page"                      
#> [19] "prelevement_ecrasant"       "producteur_donnee"         
#> [21] "size"                       "sort"                      
#> [23] "volume_max"                 "volume_min"                

# To query the endpoint "chroniques" of the API "prelevements"
# on all devices in the commune of Romilly-sur-Seine in 2018
# \dontrun{
resp <- doApiQuery(api = "prelevements",
                   endpoint = "chroniques",
                   code_commune_insee = "10323",
                   annee = "2018")
convert_list_to_tibble(resp)
#> # A tibble: 6 × 28
#>   code_ouvrage  annee volume code_usage libelle_usage         code_statut_volume
#>   <chr>         <int>  <dbl> <chr>      <chr>                 <chr>             
#> 1 OPR0000032603  2018 402383 AEP        EAU POTABLE           1                 
#> 2 OPR0000032604  2018 402383 AEP        EAU POTABLE           1                 
#> 3 OPR0000040119  2018  25174 IND        INDUSTRIE et ACTIVIT… 1                 
#> 4 OPR0000040120  2018  27242 IND        INDUSTRIE et ACTIVIT… 1                 
#> 5 OPR0000199638  2018  30588 IRR        IRRIGATION            1                 
#> 6 OPR0000333915  2018 305611 IND        INDUSTRIE et ACTIVIT… 1                 
#> # ℹ 22 more variables: libelle_statut_volume <chr>,
#> #   code_qualification_volume <chr>, libelle_qualification_volume <chr>,
#> #   code_statut_instruction <chr>, libelle_statut_instruction <chr>,
#> #   code_mode_obtention_volume <chr>, libelle_mode_obtention_volume <chr>,
#> #   prelevement_ecrasant <lgl>, producteur_donnee <chr>, longitude <dbl>,
#> #   latitude <dbl>, code_commune_insee <chr>, nom_commune <chr>,
#> #   code_departement <chr>, libelle_departement <chr>, nom_ouvrage <chr>, …
# }