Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example call to the Marvel API from js client (w/ JQuery)
// you will also have to setup the referring domains on your marvel developer portal
var PRIV_KEY = "this-should-be-a-long-hash";
var PUBLIC_KEY = "so-should-this";
function getMarvelResponse() {
// you need a new ts every request
var ts = new Date().getTime();
var hash = CryptoJS.MD5(ts + PRIV_KEY + PUBLIC_KEY).toString();
// the api deals a lot in ids rather than just the strings you want to use
var characterId = '1009718'; // wolverine
var url = 'http://gateway.marvel.com:80/v1/public/comics';
console.log(url);
$.getJSON(url, {
ts: ts,
apikey: PUBLIC_KEY,
hash: hash,
characters: characterId
})
.done(function(data) {
// sort of a long dump you will need to sort through
console.log(data);
})
.fail(function(err){
// the error codes are listed on the dev site
console.log(err);
});
};
getMarvelResponse();
@Villanuevand
Copy link

Villanuevand commented Mar 17, 2017

Following line 2 instruction:
¿How do you test in localhost?

@ia-lex
Copy link

ia-lex commented May 17, 2017

Hi, you just write 'localhost' as your authorized referrer on your developer account.

@eenesunal
Copy link

eenesunal commented Mar 25, 2019

thanks 👍

@fermmm
Copy link

fermmm commented May 15, 2020

For me it worked *.* instead of localhost

@SirCharlieMars
Copy link

SirCharlieMars commented Apr 26, 2021

This is the first API where I am required to hash anything in their query. Is this common practice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment