Please assist with AOTH code snippet?
Dear Scott,
We are seeking to use your request package for an authenticated call to Swagger.
Would it be possible for you send a code snippet, indicating how to pass the API Key.
Help much appreciated.
Kind regards, Tobe
@tobefreeman thanks for your question. it depends on how swagger expects the key to be passed. Should it be as a query parameter, or as a header? Or some other way?
Thank you very much for your reply!
We use add_headers, see below, under the r package httr . It is not returning the json payload properly. I was hoping your package might.
endpoint <- "our.address.com/api/v1/" key <-"xxxour-keyxxxxx" query <- "?query=the_query" date <- paste(queryDayYYYYMMDD, "%2003%3A34%3A23",sep="") url <- paste(endpoint,query,date,sep="") serverState <- tryCatch( jsonResponse <- GET(url, add_headers('x-api-Key' = key)), error = function(e) e )
Kind regards, Tobe
On Tue, Jun 16, 2020 at 9:06 PM Scott Chamberlain [email protected] wrote:
@tobefreeman https://github.com/tobefreeman thanks for your question. it depends on how swagger expects the key to be passed. Should it be as a query parameter, or as a header? Or some other way?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sckott/request/issues/21#issuecomment-644955961, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXOFITQ3UFEGTNPBANK6XLRW67CFANCNFSM4N7LHKIQ .
--
dr tobe freeman - +41 79 377 8595 skype/linkedin/facebook/instagram/twitter/googleplus: - tobefreeman
wordup development AG
here's an example using the service at https://httpbin.org that many use to test packages like this one, so you can see what the different parts do.
peep lets you look at the query before the query is executed. Remove peep to execute the query
api('https://httpbin.org/get') %>%
api_query(query = "foobar") %>%
api_config(verbose()) %>%
api_headers(`x-api-Key` = "your-key") %>%
peep
#> <http request>
#> url: https://httpbin.org/get
#> paths:
#> query: query=foobar
#> body:
#> paging:
#> headers:
#> x-api-Key: your-key
#> rate limit:
#> retry (n/delay (s)): /
#> error handler:
#> write:
#> config:
#> verbose: TRUE
api('https://httpbin.org/get') %>%
api_query(query = "foobar") %>%
api_config(verbose()) %>%
api_headers(`x-api-Key` = "your-key")
#> -> GET /get?query=foobar HTTP/1.1
#> -> Host: httpbin.org
#> -> User-Agent: libcurl/7.70.0 r-curl/4.3 httr/1.4.1 request/0.1.6.91
#> -> Accept-Encoding: deflate, gzip
#> -> Accept: application/json, text/xml, application/xml, */*
#> -> x-api-Key: your-key
#> ->
#> <- HTTP/1.1 200 OK
#> <- Date: Wed, 17 Jun 2020 18:40:55 GMT
#> <- Content-Type: application/json
#> <- Content-Length: 965
#> <- Connection: keep-alive
#> <- server: istio-envoy
#> <- access-control-allow-origin: *
#> <- access-control-allow-credentials: true
#> <- x-envoy-upstream-service-time: 7
#> <-
#> $args
#> $args$query
#> [1] "foobar"
#>
#>
#> $headers
#> $headers$Accept
#> [1] "application/json, text/xml, application/xml, */*"
#>
#> $headers$`Accept-Encoding`
#> [1] "deflate, gzip"
#>
#> $headers$`Content-Length`
#> [1] "0"
#>
#> $headers$Host
#> [1] "httpbin.org"
#>
#> $headers$`User-Agent`
#> [1] "libcurl/7.70.0 r-curl/4.3 httr/1.4.1 request/0.1.6.91"
#>
#> $headers$`X-Amzn-Trace-Id`
#> [1] "Root=1-5eea63b7-f0d4a45035c2f7f82dfed920"
#>
#> $headers$`X-Api-Key`
#> [1] "your-key"