BMO/REST: Difference between revisions

From MozillaWiki
< BMO
Jump to navigation Jump to search
(→‎public data: add example showing how to get all comments for a bug)
Line 27: Line 27:
Get data for a single bug
Get data for a single bug
: https://bugzilla.mozilla.org/rest/bug/35
: https://bugzilla.mozilla.org/rest/bug/35
Get all comments for a single bug
: https://bugzilla.mozilla.org/rest/bug/707428/comment


Get data for all the bugs in the 29 Branch
Get data for all the bugs in the 29 Branch

Revision as of 19:50, 20 May 2014

Bugzilla's REST API

Summary

Bugzilla has a native REST API, an HTTP version of its XMLRPC and JSONRPC APIs. It is documented along with the other WebServices and Bugzilla's internal interfaces. This is the preferred way to interface with Bugzilla from external apps, web or otherwise.

The previous REST API, BzAPI, is considered DEPRECATED. There is a compatibility layer being created to help transition away from the BzAPI server; see the BzAPI wiki page for more.

Background

Until recently, Bugzilla supported only older technologies, namely XMLRPC and JSONRPC. The BMO team created a new REST API in the summer of 2013 to provide a modern Web interface to Bugzilla.

Prior to the native REST API, a separate proxy service called BzAPI was created that provided a REST API using data obtained through the older RPC interfaces as well as various other Bugzilla data sources, including CSV representations. This was a great interim solution, but now that we have a native API, and since the system hosting the proxy is not maintained by Mozilla IT, the bzAPI service will be decommissioned at some point. See Bugzilla:API_Comparison for the differences and between bzAPI and the native API.

To ease the transition, we are creating a native bzAPI compatibility layer (bug 880669) that will act exactly the same as bzAPI but will translate the queries to the native API layer. Thus clients who currently accesses BMO data via the proxy will just need to change the REST url to move to the built-in API. The path will be slightly different depending on which API you want to use: the native one, or the one compatible with the BzAPI proxy.

There is discussion in bug 866927 about making small changes to the current upstream API that bring it closer to the format used by the BzAPI proxy. We will create individual bugs as needed for any changes that are to be made. We also plan on versioning the different API changes so that users can still continue to use an older format rather than breaking their client code.

Documentation

The REST API is documented along with the other WebServices and Bugzilla's internal interfaces.

Examples of native REST API use

public data

Here are few examples of using the API (without logging in, so with public data)

Get data for a single bug

https://bugzilla.mozilla.org/rest/bug/35

Get all comments for a single bug

https://bugzilla.mozilla.org/rest/bug/707428/comment

Get data for all the bugs in the 29 Branch

https://bugzilla.mozilla.org/rest/bug?version=29%20Branch

Get data for all the bugs assigned to a particular user

https://bugzilla.mozilla.org/rest/bug?assigned_to=lhenry@mozilla.com

Get data for all the bugs with the keyword "topcrash"

https://bugzilla.mozilla.org/rest/bug?keywords=topcrash

Get data about a particular product

https://bugzilla.mozilla.org/rest/product/firefox

Get data about products and components

https://bugzilla.mozilla.org/rest/product/core?component=DOM

Get data for a user

https://bugzilla.mozilla.org/rest/user?names=lhenry@mozilla.com

with authentication

First you need to call a /login with login=username&password=password (Docs)

# Python example, you get a token back that you can use for future calls
>>> r = requests.get('https://bugzilla.mozilla.org/rest/login?login=username&password=password')
>>> r
<Response [200]>
>>> r.text
u'{"id":272475,"token":"272345-L1KydUNCwq"}'
# Use this token to get authenticated search results
# e.g. to pull all the tracked bugs for FF31 
>>> url = 'https://bugzilla.mozilla.org/rest/bug'
# specify which fields you want so it's faster
>>> u = url + "?token=272345-L1KydUNCwq&f1=cf_tracking_firefox31&o1=equals&v1=%2B&include_fields=id"
>>> search_results = requests.get(u)
>>> search_results.text
u'{"bugs":[{"id":639524},{"id":798158},{"id":821809}]}'