Marvel API is fun

Playing with the Marvel API on and off, I really like where Marvel is going with this. The first question I seem to get when I talk about the Marvel API is “What would you use that for?”. I don’t really get that question as the uses seem pretty obvious to me. What I see is the opportunity to bring Marvel information to your users in a dynamic fashion. Covers for new comics brought in to your applications or even online articles. Connected issues or story arcs, pulled via API and updating when a character is involved in a new arc. So many possibilities.

 

It’s a RESTful API so the calls are easy. All GETs. They even give you example output to check out when you sign up as a dev. Here is an example of a call in php I used when starting:

 

$gate = ‘http://gateway.marvel.com/v1/public/’;

$APIKey =’YourAPIKey123′;

$PrivateKey = ‘YouPrivateKey123’;

$timestamp = ‘1’;

$hash = md5($timestamp . $PrivateKey . $APIKey);
$ch = curl_init($gate . “characters?name=Spider-Man” . “&ts=” . $timestamp . “&apikey=” . $APIKey . “&hash=” . $hash);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER, true );
$data = curl_exec($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpcode . ‘<br>’;

echo $gate . “characters?name=Spider-Man” . “&ts=” . $timestamp . “&apikey=” . $APIKey . $hash;

echo ‘<br>MD5 hash is: ‘ . $hash;

echo ‘<br>’;

echo ‘Time Stamp: ‘ . $timestamp;

echo ‘<br><br>’;
var_dump(
$data,
json_encode($data)
);

 

Returns fun info about a character. Pretty simple.  I am not posting a live link to this call as each visit would cost me API calls. The limit is a 1000 3000 per day. My first project may be a WP plugin to provide some of this data via short code. Since blogging about comics is something I enjoy this may prove useful. I was able to find a use for this call in a webinar I did for my job. I used Spider-Man as an example of a lead in a system that I could import into the our lead system. Was kind of fun to be able to use something more than a Jon Doe or something generic.

 

If I create a plugin of WP I will write about the plugin source code and it’s creation. If you have created anything with the Marvel API please let me know! I would love to check it out.





Comments are closed.