I am trying to download some data from an API. Following the site documentation:
library(jsonlite)
document <- fromJSON("https://api.gurufocus.com/public/user/{your personal token?}/stock/WMT/keyratios");
epv <- document$Valuation$`EPV`
cat(epv)
I inserted my token, but unfortunately, I get this error: Error in open.connection(con, "rb") : HTTP error 404.
Any idea to solve this problem?
Best regards
CodePudding user response:
Up front: remove the {
, ?}
from the url.
Replace more of the string. If you notice in their examples:
Request
Method URL
GET https://api.gurufocus.com/public/user/{your personal token?}/stock/{symbol?}/financials
Example https://api.gurufocus.com/public/user/{your personal token?}/stock/WMT/financials
The {symbol?}
is replaced with WMT
. I'm inferring you need to do with same with your token.
If I call
https://api.gurufocus.com/public/user/{abcd1234?}/stock/WMT/financials
(where abcd1234
is a known fake token), I get a 404 Not Found. I believe this is because the question mark breaks the URL into a path component
https://api.gurufocus.com/public/user/{abcd1234
and arguments
}/stock/WMT/financials
However, when I do:
https://api.gurufocus.com/public/user/abcd1234/stock/WMT/financials
I get a 401 Unauthorized, meaning that it parsed a token out of it, found the endpoint, and the token is not sufficient (which I know) to authorize access.