"You must provide a hash." error when using API to download data (in R)

Tal Reznik picture Tal Reznik · Feb 26, 2015 · Viewed 9.7k times · Source

I would like to extract the data from MARVEL DEVELOPER by API code and analyze it (using R).

I got the following url from MARVEL website: http://gateway.marvel.com:80/v1/public/characters?apikey=f389fcb49ad574e10ca570867f4bfa43

I used httr package to collect the data:

install.packages("httr")
library(httr)
> url <- GET("http://gateway.marvel.com:80/v1/public/characters?orderBy=name&limit=100&apikey=f389fcb49ad574e10ca570867f4bfa43")
> content(url)
$code
[1] "MissingParameter"

$message
[1] "You must provide a hash."

I want to extract all this data to R. What should I do/read?

Thanks.

Answer

bergant picture bergant · Feb 26, 2015

You have to provide ts (timestamp) and hash parameter. Hash is (according to documentation) = md5(ts+privateKey+publicKey)

You can compute md5 with:

library(digest)
hash <- digest(paste0(ts, privateKey, publicKey), algo="md5")

Server-side applications must pass two parameters in addition to the apikey parameter:

ts - a timestamp (or other long string which can change on a request-by-request basis)

hash - a md5 digest of the ts parameter, your private key and your public

key (e.g. md5(ts+privateKey+publicKey) For example, a user with a public key of "1234" and a private key of "abcd" could construct a valid call as follows:

http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150 (the hash value is the md5 digest of 1abcd1234)