Phish.net API Wrappers: PHP

The following wrapper function can communicate with the Phish.net API using cURL. Include this function in any page to establish a connection with phish.net.<?php
$myapikey ='XXXXX';
function pnet_api_req($data, $method=false) {
if(!$method && isset($data['method'])) {
// you can pass the method as an element of the data array
// or you can use it as an argument in the function
$method= "/".str_replace(".","/",$data['method']);
}
$ch = curl_init('https://api.phish.net/v3'.$method);
curl_setopt($ch, CURLOPT_POST,true);
if(is_array($data)) { $data = http_build_query($data); }
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // RETURN THE CONTENTS OF THE CALL
return curl_exec($ch);
}

The next step is to send data to the function. Here is an example method call:<?php
$data = [
'apikey'=>$myapikey,
'method'=>'setlists.latest'
];
$arr = @json_decode(pnet_api_req($data),true); //set to true for an array or false for an object
if(is_array($arr)) { var_dump($arr); } else { error_log('Unable to fetch phish.net API :('; }

This should provide you the infrastructure to communicate with the phish.net API using any method, including the writeable methods.

Donate to Mockingbird

Contact Us

The Mockingbird Foundation

The Mockingbird Foundation is a non-profit organization founded by Phish fans in 1996 to generate charitable proceeds from the Phish community.

And since we're entirely volunteer – with no office, salaries, or paid staff – administrative costs are less than 2% of revenues! So far, we've distributed over $1,000,000 to support music education for children – hundreds of grants in all 50 states, with more on the way.