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

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.