2

I have a JSON URl - https://{{API_HOST}}/api/dd/new which needs to be parsed in R. It has a Key and Value, Through which I am easily able to parse the JSON in Postman by applying key and value in Headers section. Looking a way to do the same in R using Key and Value.

I am aware about how to parse JSON using basic authentication.

Code:

library(jsonlite)
library(httr)

Url <- "https://{{API_HOST}}/api/dd/new"

Url.Response <- GET(Url,authenticate("string","password"))

RawJson <- rawToChar(Url.Response$content)

JsonData <- fromJSON(RawJson)

JsonDataDf  <- as.data.frame(JsonData)

Looking for similar way in R to parse the JSON Url using Key and Value. Do add_headers will help here. Let the Key be STRING, Value be qwertzuiop

Community
  • 1
  • 1
string
  • 787
  • 10
  • 39

1 Answers1

1

Able to resolve this, Below is the solution:

library(httr)
library(jsonlite)

getURL <- "https://{{API_HOST}}/api/dd/new"

auth_key <- "qwertzuiop"

RESTQuery = getURL

RESTGETHeader = c(
'STRING'=auth_key,
'Accept'="application/json"
)

RESTResult <- GET(RESTQuery,add_headers(RESTGETHeader))

RawJson <- rawToChar(RESTResult$content)

JsonData <- fromJSON(RawJson)

JsonDataDf  <- as.data.frame(JsonData)
string
  • 787
  • 10
  • 39