From a Secure Endpoint

First, follow the authentication and authorization setup procedure .

Then, in R studio, obtain the AzureAuth library and follow the example code below

library(AzureAuth)
library(httr)
library(jsonlite)


#xMart UAT https://portal-uat.who.int/xmart-api/odata/{mart_code}
# authn_resource <- "b85362d6-c259-490b-bd51-c0a730011bef" # client id of xMart API as registered in WHO AAD
# authn_tenant <- "f610c0b7-bd24-4b39-810b-3dc280afb590" # tenant id of WHO as registered in WHO AAD
# authn_app <- "xxxx" # client id of the application consuming data from xMart API (as registered in WHO AAD)
# authn_password <- "yyyy" # client secret application consuming data from xMart API
# authn_auth_type <- "client_credentials"
# authn_use_cache <- TRUE


#@xMart PROD
authn_resource <- "712b0d0d-f9c5-4b7a-80d6-8a83ee014bca" # client id of xMart API as registered in WHO AAD
authn_tenant <- "f610c0b7-bd24-4b39-810b-3dc280afb590" # tenant id of WHO as registered in WHO AAD
authn_app <- "xxxx" # client id of the application consuming data from xMart API (as registered in WHO AAD)
authn_password <- "yyyy" # client secret application consuming data from xMart API
authn_auth_type <- "client_credentials"
authn_use_cache <- TRUE


tok0 <- get_azure_token(resource=authn_resource,
                        tenant=authn_tenant,
                        app=authn_app,
                        auth_type=authn_auth_type,
                        password=authn_password ,
                        use_cache=authn_use_cache)

list_azure_tokens()


access_token <- tok0$credentials$access_token
bearer <- paste("Bearer", access_token)
print(bearer)

headers <- add_headers(Authorization = bearer)

# Replace the MART_CODE and OBJECT_CODE (code of the table or view) with your mart and object codes.
response <- GET("https://portal-uat.who.int/xmart-api/odata/MART_CODE/OBJECT_CODE", headers)
json <- content(response, "text")
the_data <- fromJSON(json)
the_data