JSON API » Sample clients » PHP

#!/usr/bin/php
<?php

# This is a sample client for the Enswitch JSON API.
# It is released into the public domain.
# It comes with absolutely no warranty, and is not supported.

$base = 'http://enswitch.example.com/api/json/';
$function = 'access/list';
$username = 'testuser';
$password = 'testpass';

$reply = file_get_contents( $base . $function . '/?auth_username=' . $username . ';auth_password=' . $password );
$output = json_decode( $reply, true );
$fatal = 0;
foreach( $output[ 'responses' ] as $r ) {
	if ( intval( $r[ 'code' ] ) >= 400 ) {
		error_log( $r[ 'message' ] );
		$fatal = 1;
	}
}
if ( $fatal ) {
	exit( 1 );
}

foreach( $output[ 'data' ] as $d ) {
	echo 'Remote access account id=', $d[ 'id' ], ', name=', $d[ 'name' ], ".\n";
}
?>