Phish.net API v5 Documentation

Table of Contents


Unlike prior versions of the Phish.net API, version 5 does not feature hosted callback functions.

What is a Callback?

When returning JSON - which is just javascript - via an API, web pages (for starters, but also apps, etc.), need to process that raw data. This is often done by "wrapping" the returned data in a callback. A callback is a function name.

Usage

If you defined a function called myFunction, you might want to feed the data from an API into that function. If the returned data were loaded into a string, say, data, the call would look like this: myFunction(data).

We can "shortcut" this with a callback. If your API call includes an argument called callback, the result will be wrapped in that function.

Example Callback

Below is an example callback that takes a call to the setlists endpoint of our v5 API, turns it into HTML, and dynamically fills is an element with an id of setlist.

if( typeof phishnet_setlist == "undefined" ) {
    function phishnet_setlist(json) {
        last_set = 0;
        el = document.getElementById('setlist');
        setString = '';
        el.innerHTML = "<h3><a href='"
            + json.data[0].permalink + "'>" + json.data[0].artist_name + " &mdash; "+json.data[0].showdate + " " + json.data[0].venue + ", "
            + json.data[0].city + ", " + json.data[0].state + "</a></h3>"
        for(i=0;i<json.data.length;i++) {
            var n = json.data[i];
            if(last_set!=n.set) {
                if(1!=n.set) { setString += "</p>"; }
                if(1==n.set || 2==n.set || 3==n.set || 4==n.set) {
                    setString +=    "<p><b>Set "+n.set+":</b> ";
                } else if('e3'==n.set) {
                    setString +=    "<p><b>Encore 3:</b> ";
                } else if('e2'==n.set) {
                    setString +=    "<p><b>Encore 2:</b> ";
                } else {
                    setString +=    "<p><b>Encore:</b> ";
                }
            }
            setString += " <a href='https://phish.net/song/"+ n.slug + "'";
            if(1==n.isjamchart) {
                setString += " style='color:#f00;' title='"+n.jamchart_description.replace(/\"/g, "&quot;").replace(/\'/g, "&apos;")+"'";
            } else {
                setString += " title='"+n.song+"'";
            }
            setString += ">"+n.song+"</a>";
            setString += n.trans_mark;
            last_set = n.set;
        }
        el.innerHTML += setString + "</p>"
        if(n.setlistnotes.replace(/^\s+|\s+$/g,"")!='') { el.innerHTML += "<p class='pnetsn'>" + n.setlistnotes + "</p>"; }
    }
}

Example Use

<script>
    // you should replace this with a function like the one above
    function myFunction(json) { }
</script>
<div id="setlist"></div>
<script src="https://api.phish.net/v5/setlists/showdate/1997-11-22.json?apikey=YOUR_API_KEY&callback=myFunction"></script>