I have tried to return a JSON response using an API call in RStudio. Its returning the desired JSON file in Postman but the httr API calls don't seem to be returning anything which I can parse into a dataframe.
This is the call in r using the httr package:
req <-
httr::POST("https://api2.elasticgrid.com/api/v1/analytics/vendor/partnerengagement/advanced/all",
httr::add_headers(
"Authorization" = "Bearer <long string>"
),
body = "VendorId=80&TimeFrame=AddMonths(-3)&Language=en-US",encode="json"
);
This returns a List of 10, but nothing useful and I am fairly sure the JSON content is not hiding in the list
I've tried:
js <- fromJSON(content(req,as="text"))
But, this is returning "An error has occurred"
or:
json <- httr::content(req, as = "parsed")
But this returns a non-discript key "7b 22 4d..."
This is the working API call in Postman (RAW HTTP version shown):
POST /api/v1/analytics/vendor/collateral/advanced/all HTTP/1.1
Host: api2.elasticgrid.com
Authorization: Bearer <long string>
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: <token>
{
"VendorId": 80,
"TimeFrame": "AddMonths(-3)",
"Language": "en-US"
}
Can anyone point me in the right direction to parse a JSON into a dataframe based on an r API call. I've tried a few packages and resources already but am really not sure what to try next assuming this is possible.