Skip to content

Instantly share code, notes, and snippets.

@stpe
Created March 17, 2012 22:26
Show Gist options
  • Save stpe/2065862 to your computer and use it in GitHub Desktop.
Save stpe/2065862 to your computer and use it in GitHub Desktop.
Simple JSON wrapper of Mantis SOAP API
<?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);
@Ashwin-Kapes
Copy link

Is this possible with REST instead of SOAP? I'm unable to authenticate using username, password or API token when using REST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment