Joseph
June 23, 2016
4 mins to read


Following up on Part 1, this is my series on learning how to use Comic Vine API. In the first post, I talked about basic API set-up, obtaining your own API key, making basic API calls, sorting the data returned, and limiting fields returned using the filed list. T

Below is the information that will help you understand these posts.

Formatting and Resource information

Abbreviations

url = The Comic Vine API address is http://comicvine.gamespot.com/api

your_apikey = Your Personal API Key. Can be acquired here.

<resource> = The Comic Vine Resources, sample below

<field_list> = Any field within the resource being called

Sample of API Resources

Each resource as a plural and singular component. In most API calls, you will use the plural to have the call return a list of  the singular.

Character (s)         Issue (s)

Publisher (s)          Series/ Series_List

Team (s)                 Volume (s)

Search

Okay, finally, some Comic Vine API Examples…..

Lets start with a basic call with a filter.

url/<resource>/?api_key=your_apikey &filter=<field_list>: (filter statement)

By design, Comic Vine does not use all fields in a resource to filter data. It is important to review the API resources to see which fields can be used.

Now, lets create a call to start pulling back some characters. Lets filter the data to return just the females.

url/characters/?api_key=your_apikey&filter=gender:female

Our first character returned from the above call is: Dream Girl


<?xml version="1.0" encoding="utf-8"?>
    <response>
    <error>
    <![CDATA[ OK ]]>
    </error>
    <limit>100</limit>
    <offset>0</offset>
    <number_of_page_results>100</number_of_page_results>
    <number_of_total_results>18430</number_of_total_results>
    <status_code>1</status_code>
    <results>
        <character>
            <aliases>...</aliases>
            <api_detail_url>...</api_detail_url>
            <birth/>     <count_of_issue_appearances>341</count_of_issue_appearances>
            <date_added>2008-06-06 11:27:38</date_added>
            <date_last_updated>2013-03-20 20:06:16</date_last_updated>
            <deck>...</deck>
            <description>...</description>
            <first_appeared_in_issue>...</first_appeared_in_issue>
            <gender>2</gender>
            <id1254</id>
            <image>...</image>
            <name>
                <[CDATA[ Dream Girl ]]>
            </name>

To improve this call, lets add structure to the previous call  with a sort, the format for this is:

url/<resource>/?api_key=your_apikey&filter=<field_list>:(filter statement)&sort=<field_list>: (direction)

The below call is an example for looking for males and sort them descending by name:

url/characters/?api_key=YOUR_APIKEY&filter=gender:female&sort=name: desc

This time our first response is ZZasha!?!


<?xml version="1.0" encoding="utf-8"?>
        <gender>2</gender>
        <id>32696</id>
        <image>...</image>
        <name>
            <[<![CDATA[ Zzasha ]]>>
        </name>

But, let’s improve this call with an additional filter. There are two ways we can do this:

Adding an additional filter statement

&filter=<field_list>: (filter statement) & filter=<field_list>: (filter statement)

Placing commas “,” between the filters

&filter=<field_list>: (filter statement) , <field_list>: (filter statement)

So, lets see if we can find my favorite character Hawkeye. We will use the below call:

url/characters/?api_key=your_apikey& filter=gender:male,name:hawkeye

Yep. It returned Hawkeye…. and Sagittarius (Hawkeye LMD).  Where did this other Hawkeye come from…. Oh, the Zodiac copy!!!


<?xml version="1.0" encoding="utf-8"?>
    <response>
    <error>
        <![CDATA[ OK ]]>
    </error>
    <limit>100</limit>
    <offset>0</offset>
    <number_of_page_results>2</number_of_page_results>
    <number_of_total_results>2</number_of_total_results>
    <status_code>1</status_code>
    <results>
        <character>...</character>
        <character>
            <aliases/>
            <api_detail_url>...</api_detail_url>
            <birth/>
            <count_of_issue_appearances>4</count_of_issue_appearances>
            <date_added>2013-05-17 20:10:07</date_added>
            <date_last_updated>2013-05-17 21:49:04</date_last_updated>
            <deck>...</deck>
            <description>...</description>
            <first_appeared_in_issue>...</first_appeared_in_issue>
            <gender>1</gender>
            <id>89494</id>
            <image>...</image>
            <name>
                <![CDATA[ Sagittarius (Hawkeye LMD) ]]>
            </name>

With the previous call returning both Hawkeye and Sagittarius (Hawkeye LMD), this shows that filters are not looking for exact matches. These filters are looking for the given string within the Field_List.

Lastly, lets make a final call to pull back all the “X-Men” volumes with only the name field. To do this, we will add a to the call to pull back only the name.

url/characters/?api_key=your_apikey& filter=name: X-men&field_list=name


<?xml version="1.0" encoding="utf-8"?>
    <results>
    <volume>
        <name>
            <![CDATA[ The X-Men ]]>
        </name>
    </volume>
    <volume>
        <name>
            <![CDATA[ Giant-Size X-Men ]]>
        </name>
    </volume>
    <volume>
        <name>
            <![CDATA[ The Uncanny X-Men ]]>
        </name>
    </volume>
    <volume>
        <name>
            <![CDATA[ X-Men Classics Starring the X-Men ]]>
        </name>
    </volume>
    <volume>
        <name>
            <![CDATA[ The X-Men and The Micronauts ]]>
        </name>
    </volume>

At this point we have covered a lot of the basic components of making API calls Comic Vine’s API. We can Sort, Filter, and limit fields. The next couple posts we will start looking at pagination and maneuvering though all the data instead of just looking at the first response. To do this, we might need to start adding some programming to help with this. Versus, just typing URLs into a browser.

Recent Posts