Wednesday, February 2, 2011

Bugzilla API Request via PHP

Have you tried to use the Bugzilla API and fell flat on the face unless you are using Python, Perl, C#, Java or anything but PHP (I still like PHP). Sadly I couldn't get any XMLRPC clients to work with the xmlrpc.cgi because prior to 3.6 versions of the API, Bugzilla authenticated via cookies. Zend Framework seems to support this but it also happens to be a lot of work just to create a ticket. Well fear not, I RTFM over and over and found this little note:


You can specify Bugzilla_login and Bugzilla_password as arguments to any WebService method, and you will be logged in as that user if your credentials are correct.

in http://www.bugzilla.org/docs/3.6/en/html/api/Bugzilla/WebService.html

Documented in a very obscure place and 3.6 documentation is not the first to come up on Google. Here is some code via Codeigniter that does the trick but I assume any XMLRPC client will do the job with this concept.

$this->load->library('xmlrpc');
$this->xmlrpc->server('http://bugzilla.yoursite.com/xmlrpc.cgi', 80);
$this->xmlrpc->method('User.login');

$request = array('Bugzilla_login'=>'user@example.com', 'Bugzilla_password'=>'your_password', 'product'=>'Your Product Name', 'component'=>'User Submitted', 'summary'=>'Test', 'version'=>'x.x', 'description'=>'asdas');

$this->xmlrpc->method('Bug.create');
$this->xmlrpc->request(array(array($request, 'struct')),'struct');

if(!$this->xmlrpc->send_request()) {
echo $this->xmlrpc->display_error();
}

// this returns ticket ID
print_r($this->xmlrpc->display_response());

Enjoy this, took me a while to figure it out.
B

3 comments:

mkanat said...

I'm glad you did get that figured out--I didn't realize that that documentation was so hard to find! Your post inspired me to create a centralized wiki page where all the WebService documentation is linked from, so that people can find it more easily:

https://wiki.mozilla.org/Bugzilla:WebService

-Max

Boris Cosic said...

That's awesome and thanks a lot. Loving Bugzilla.
B

Gautam Kakdiya said...

Thank's Boris Cosic's, That's awesome and thanks a lot...

Post a Comment