Meraki API – With PHP for beginners

Here is a simple php page to list all you network inside your organization.

You just need to put in your org number and API Key.

    $apikey = 'INSERT API KEY HERE';

    $url = "".$org."/networks";

    $headr = array();
    $headr[] = 'Content-Type: application/json';
    $headr[] = 'X-Cisco-Meraki-API-Key:  '.$apikey;

    //cURL starts
    $crl = curl_init();
    curl_setopt($crl, CURLOPT_URL, $url);
    curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($crl, CURLOPT_HTTPGET,true);
    curl_setopt($crl, CURLOPT_FOLLOWLOCATION, true);
    $reply = curl_exec($crl);

    //error handling for cURL
    if ($reply === false) {
       // throw new Exception('Curl error: ' . curl_error($crl));
       print_r('Curl error: ' . curl_error($crl));
    //cURL ends
    //decoding the json data

    $data =  json_decode($reply);

<h1>Network overview:</h1>
<table width='600px' border='1'>

			foreach ($data as $value) {
				echo '<tr>';
				echo '<td>' . utf8_decode($value->name) . '</td>';
				echo '<td>' . $value->type . '</td>';
				echo '</tr>';

Leave a Reply