Back to Home

Communication between web application and MantisBT

Mantis · mantisconnect.php · SOAP · helpdesk

Communication between web application and MantisBT

Using Mantis to account for applications from subscribers, one often faced the following difficulties:
1) When adding a new application, you have to enter or copy part of the information from the client’s card in Mantis, which is, firstly, laziness, and secondly, can potentially lead to distortion information.
2) It is not always possible to quickly read previous applications for this subscriber, firstly, because laziness, and secondly, see paragraph one, regarding distorted information.

To solve this problem, we will use the Mantis API - mantisconnect.php.

Start

The mention of this API slipped both on the hub and on the mantisbt forum, but the problem was that all the conversations focused on the fact that “everything is simple there”, but for me as a non-programmer, it was not very easy to understand with what to start. Looking ahead, I can say that everything is really simple there, I will try to talk about it.

Mantis’s API uses the SOAP protocol. To work with it, we need either an external NuSOAP library, or you can use the standard extension php_soap. You can see what is in this API here:
http://www.mantisbt.org/bugs/api/soap/mantisconnect.php
http://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl

Now let's figure out what to do with all this wealth.

We need to write a php script in which:
1) Create a SOAP client

$client = new nusoap_client($WSDL_POINT, false);

$WSDL_POINT- this is the url of the location of mantisconnect.php in your tracker, http: // [site] /api/soap/mantisconnect.php?wsdl

2) Use the created client for our selfish purposes. As an example, we use the simplest function - view version ( mc_version)

$result = $client->call('mc_version', 'http://localhost/mantis/api/soap/mantisconnect.php', 'http://soap.amazon.com');

The result will be a line with the version of the bugtracker.

If we try to get information about a specific incident, we get the following script:

 $username,
	'password' => $password,
	'issue_id' => $issue_id
);
$client = new nusoap_client($WSDL_POINT, false);
$result = $client->call('mc_issue_get', $params, 'http://localhost/mantis/api/soap/mantisconnect.php', 'http://soap.amazon.com');
echo "
";
print_r ($result);
echo "
"; ?>

$params- an array of input variables. To receive an incident, as can be seen from the description in the api, we need a username, password and incident number.

The result will be an associative array with all the data related to this incident. You can see it by function print_r(). We can pick up the required fields as elements of an array.

Here we can quite possibly encounter a problem - instead of an array with an incident, an array with an error may arrive to us:
Array
(
    [faultcode] => Server
    [faultactor] => 
    [faultstring] => Error Type: SYSTEM NOTICE,
Error Description:
Use of undefined constant ERROR_DUPLICATE_FILE - assumed 'ERROR_DUPLICATE_FILE',)

The problem appears if in the settings of the user account whose username / password is used to "communicate" with Mantis, the language settings indicate any language other than English. This is due to the fact that the code in the mantis was changed, and the localization files were not corrected.

The situation can be corrected in the following ways:

1) set the English language in the settings;
2) wait for version 1.2.11, where they promise to fix it, or upgrade to a nightly build;
3) fix the localization file /lang/strings_russian.txtyourself - enclosing ERROR_DUPLICATE_FILEin single quotes.

Create Request

Having looked at what constitutes an array with an incident, we can compose the same in order to create an incident. In addition, those fields that you do not specify in the incoming array will be automatically updated by default.

Suppose to create an application, from the subscriber’s card, we need:

1) his name;
2) login.

Plus the reason for the appeal.

We will put the login in the specially created login field.
We get the following array:

$issue_data = array(
	'project' => array (
		'id' => 1 
	),
	'category' => "general",
	'reporter' => array (
		'id' => $reporter_id
	),
	'summary' => $summary,
	'description' => $description,
	'custom_fields' => array ($sequence_login_field => array (
			'field' => array (
				'id' => $login_field_id 
				),
				'value' => $login 
		              ),
		)
);

project_id= 1 - id of the project to which we are adding the incident
$reporter_id- Yes, we can substitute any user in this place, conveniently, because we will not need to know the passwords of
all employees
$summary- it consists of a full name and possibly additional. information
$description- the reason for contacting
$sequence_login_field, $login_field_id- to be taken from Mantis
$login- the subscriber’s login from the client’s card

Next, we put this array in $ params
$params = array(
    'username' => $username,
    'password' => $password,
    'issue' => $issue_data
);

and feel free to ship. In response, the number of the created incident will be returned to us.

Incident Information

When we have the subscriber’s login in all created applications (the login is unique), when we open the client’s card, we can perform another soap request to Mantis, namely a search request to show us all the incidents related to this subscriber.

Unfortunately, there is no such request that you can search in the mantis database, but you can use a pre-created ready-made filter. In my case, I created a filter for 1000 incidents with all statuses except “closed” and sorted in ascending order of time of the last incident change.

$params = array(
    'username' => $username,
    'password' => $password,
    'project_id' => 1,
    'filter_id' => $filter_id,
    'page_number' => 1,
    'per_page' => 100	
); 


As a result, I accept an array of 100 incidents, and I can only display on the screen those whose login matches the one specified in this client card.

Read Next