Skip to content

Instantly share code, notes, and snippets.

@kehh
Forked from stpe/mantisconnect_json.php
Last active August 29, 2015 14:10
Show Gist options
  • Save kehh/f36cb168d398de12bdeb to your computer and use it in GitHub Desktop.
Save kehh/f36cb168d398de12bdeb to your computer and use it in GitHub Desktop.
<?php
/**
* Example usage (using jQuery):
* var url = "/path/mantisconnect_json.php?name=mc_project_get_issues&project_id=0&page_number=1&per_page=10";
* $.getJSON(url, function(data) {
* $.each(data, function() {
* console.log(data.id + ': ' data.summary);
* });
* });
*/
// URL to your Mantis SOAP API (the mantisconnect.php file)
define('MANTISCONNECT_URL', 'http://www.whereyouhaveyourmantis.com/api/soap/mantisconnect.php');
// the username/password of the user account to use for calls
define('USERNAME', 'yourmantislogin');
define('PASSWORD', 'yourmantisloginpassword');
// ------------------------------------------------
parse_str($_SERVER['QUERY_STRING'], $args);
// get SOAP function name to call
if (!isset($args['name'])) {
die("No name specified.");
}
$function_name = $args['name'];
// remove function name from arguments
unset($args['name']);
// prepend username/passwords to arguments
$args = array_merge(
array(
'username' => USERNAME,
'password' => PASSWORD
),
$args
);
// connect and do the SOAP call
try {
$client = new SoapClient(MANTISCONNECT_URL . '?wsdl');
$result = $client->__soapCall($function_name, $args);
} catch (SoapFault $e) {
$result = array(
'error' => $e->faultstring
);
}
print json_encode($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment