programically create ticket

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
mentis
Posts: 11
Joined: 31 Dec 2012, 18:49

programically create ticket

Post by mentis »

hello,
I am in desperate need of creating a plugin that would enable me and my users to create tickets and adding comments to them via JSON@POST.
In other words. I want to be able to send a POST request containing a JSON to plugin page. I want this page to create a ticket/bug and necessary comments.
I made a upload.php that is available from my plugin dir. It contains:

Code: Select all

<?php
	if(isset($_POST['ticket'])) {	
		$ticket = json_decode($_POST['ticket']);
		if($ticket) {
			$insert = "insert into " . plugin_table( "alerts" );
			$insert .= " set ";
...
         makeTicket($ticket);
makeTicket more or less like...

Code: Select all

function makeTicket($ticket) {
		
		$a_alarm = 37;
		$a_adm = 31;
		$a_awaria = 40;		
		$alarmy = new Alarmy();
		
		if(in_array($ticket->typAlarmu,$alarmy->low)) {
			$now = date("Y-m-d H:i:s");
			$summary = 'Raport dzienny, alarmy niskie, ' . $now;			
			$bug = myBug($a_alarm,$summary);
			$bugId = $bug->create();			
			$f_private		= false;
			$f_time_tracking	= '0:00';
                        $f_bugnote_text = 'stuff';			
			$noteId = bugnote_add( $bugId, $f_bugnote_text, $f_time_tracking, $f_private, 0 );						
		}
}
mybug looks like...

Code: Select all

function myBug($category, $summary) {
	
		$bug = new BugData;
		$bug->build					= '';
		$bug->platform				= '';
		$bug->os					= '';
		$bug->os_build				= '';
		$bug->version				= '';
		$bug->profile_id			= 0;
		$bug->handler_id			= 0;
		$bug->view_state			= 10; //gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );//10;
		$bug->project_id			= 2;
		$bug->reporter_id			= 1;
		$bug->duplicate_id			= 0;
		$bug->sponsorship_total		= 0;
		$bug->sticky				= 0;
		$bug->category_id			= $category;
		$bug->reproducibility		= 70; //gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );//70;
		$bug->severity				= 50; //gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );//50;
		$bug->priority				= 30; //gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );//30;
		$bug->projection			= 10; //gpc_get_int( 'projection', config_get( 'default_bug_projection' ) );//10;
		$bug->eta					= 10; //gpc_get_int( 'eta', config_get( 'default_bug_eta' ) );//10;
		$bug->resolution			= 10; //config_get( 'default_bug_resolution' );//10;
		$bug->status				= 10; //config_get( 'bug_submit_status' );//10;
		$bug->summary				= $summary; //'Alarm średni, ' . $ticket->nazwaAlarmu . ', #(' . $ticket->identyfikator . ')' ; 
		$bug->description			= $summary; //'Alarm średni, ' . $ticket->nazwaAlarmu . ', #(' . $ticket->identyfikator . ')' ; 
		$bug->steps_to_reproduce	= '';
		$bug->additional_information	= '';
		$bug->due_date 				= 1;	
		return $bug;		
	}
I can open a bug, however I cant add a bugnote. What am I missing ?
Can this be completed in another way ? i.e. Is there some kind of API for creating a bug?
rombert
Posts: 66
Joined: 05 Nov 2009, 08:43

Re: programically create ticket

Post by rombert »

There is a SOAP API you can use. Please see the SOAP section in the MantisBT manual for details.
mentis
Posts: 11
Joined: 31 Dec 2012, 18:49

Re: programically create ticket

Post by mentis »

I'm new to soap,
is there some kind of example of how to use this api?

I already went through some general soap API examples on the web, but they seam different, definitely not as easy as:

Code: Select all

        $client = new SoapClient("http://buka/mantis_aron/api/soap/mantisconnect.php?wsdl",array('features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => true));
	echo "<pre>";
	echo $client->mc_version();
	echo "<br>";
	echo $client->mc_enum_status();
	echo "<br>";
	echo $clint->__soapCall('mc_issue_get_biggest_id',array('username' => 'user', 'password' => 'pass', 'project_id' => 2));
	echo $client->mc_issue_get_biggest_id(array('username' => 'user', 'password' => 'pass'));


cuz Im getting

Code: Select all

Fatal error: Uncaught SoapFault exception: [Client] Access denied
mentis
Posts: 11
Joined: 31 Dec 2012, 18:49

Re: programically create ticket

Post by mentis »

according to this

http://stackoverflow.com/questions/9226 ... mmatically

this should work

Code: Select all

$client = new SoapClient("http://buka/mantis/api/soap/mantisconnect.php?wsdl");
echo $clint->mc_issue_get_biggest_id('user','dupa',2);
but all I get is:
Fatal error: Call to a member function mc_issue_get_biggest_id() on a non-object in /var/www/mantis/plugins/dyzurny/pages/soapTest.php on line 17
?

Code: Select all

php -i | grep soap
soap
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400
PWD => /var/www/mantis_aron/api/soap
_SERVER["PWD"] => /var/www/mantis_aron/api/soap

php -v
PHP 5.4.16-1~dotdeb.1 (cli) (built: Jun  8 2013 22:07:31) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
mentis
Posts: 11
Joined: 31 Dec 2012, 18:49

Re: programically create ticket

Post by mentis »

I used
http://code.google.com/p/wsdl2phpgenerator/

its alive !
xD

- edit

its not... I'm getting err like

http://www.mantisbt.org/bugs/view.php?id=14157
Post Reply