Difference between revisions of "Bugzilla:BzAPI"
Line 13: | Line 13: | ||
Older pages in this wiki document released versions of BzAPI. | Older pages in this wiki document released versions of BzAPI. | ||
− | ===Version 0.6 ( | + | ===Version 0.6.1 (13th July 2010)=== |
+ | |||
+ | This is version 0.6, updated for Bugzilla 3.6 compatibility. Two things don't work: JSONP, and the new_since parameter for the /comment call. | ||
* [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API&oldid=215695 Overview] | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API&oldid=215695 Overview] | ||
Line 22: | Line 24: | ||
* [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:HowTo&oldid=185641 Tips, tricks and code samples] | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:HowTo&oldid=185641 Tips, tricks and code samples] | ||
− | ===Version 0. | + | ===Version 0.7 (14th September 2010)=== |
− | |||
− | |||
* [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API&oldid=215695 Overview] | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API&oldid=215695 Overview] | ||
− | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Methods&oldid= | + | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Methods&oldid=255909 API Methods] |
** [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Search&oldid=189990 Parameters for the Search method] | ** [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Search&oldid=189990 Parameters for the Search method] | ||
− | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Objects&oldid= | + | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Objects&oldid=237834 Objects sent and received] |
** [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Objects:Configuration&oldid=209065 The Configuration object] | ** [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:Objects:Configuration&oldid=209065 The Configuration object] | ||
− | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:HowTo&oldid= | + | * [https://wiki.mozilla.org/index.php?title=Bugzilla:REST_API:HowTo&oldid=254262 Tips, tricks and code samples] |
==Servers== | ==Servers== | ||
Line 39: | Line 39: | ||
Main Mozilla server (https://bugzilla.mozilla.org/): | Main Mozilla server (https://bugzilla.mozilla.org/): | ||
− | [https://api-dev.bugzilla.mozilla.org/0. | + | [https://api-dev.bugzilla.mozilla.org/0.7/ https://api-dev.bugzilla.mozilla.org/0.7/] |
[https://api-dev.bugzilla.mozilla.org/latest/ https://api-dev.bugzilla.mozilla.org/latest/] | [https://api-dev.bugzilla.mozilla.org/latest/ https://api-dev.bugzilla.mozilla.org/latest/] | ||
Testing server (http://landfill.bugzilla.org/bzapi_sandbox/): | Testing server (http://landfill.bugzilla.org/bzapi_sandbox/): | ||
− | [https://api-dev.bugzilla.mozilla.org/test/0. | + | [https://api-dev.bugzilla.mozilla.org/test/0.7/ https://api-dev.bugzilla.mozilla.org/test/0.7/] |
[https://api-dev.bugzilla.mozilla.org/test/latest/ https://api-dev.bugzilla.mozilla.org/test/latest/] | [https://api-dev.bugzilla.mozilla.org/test/latest/ https://api-dev.bugzilla.mozilla.org/test/latest/] | ||
Revision as of 12:56, 27 September 2010
These pages document the tip of the HTTP REST API for Bugzilla proxy software ("BzAPI"). Please file bugs (in either code or documentation) in the BzAPI component in bugzilla.mozilla.org.
This page contains general information and preliminaries. Read it first. Then, you can find more detailed information:
Contents
Versions
Older pages in this wiki document released versions of BzAPI.
Version 0.6.1 (13th July 2010)
This is version 0.6, updated for Bugzilla 3.6 compatibility. Two things don't work: JSONP, and the new_since parameter for the /comment call.
Version 0.7 (14th September 2010)
Servers
Installations of the API are available pointed at two Bugzilla servers - the main Mozilla one and the testing server. Please use the testing server for testing API clients. You can also use a specific version of the API, or just "the latest version".
Main Mozilla server (https://bugzilla.mozilla.org/):
https://api-dev.bugzilla.mozilla.org/0.7/ https://api-dev.bugzilla.mozilla.org/latest/
Testing server (http://landfill.bugzilla.org/bzapi_sandbox/):
https://api-dev.bugzilla.mozilla.org/test/0.7/ https://api-dev.bugzilla.mozilla.org/test/latest/
If you want to always use the same version, use URLs with a version number in. However, old ones are not guaranteed to persist. If you want to live on the edge, use URLs with "latest" in. However, backwardly-incompatible changes are possible at the time of a new release.
Authors of API-using tools are strongly encouraged to join the mozilla.tools mailing list to be kept up to date on changes and new releases.
Browsing the API
If the Accept: header of a request is set to text/html (as it is by an ordinary web browser) then the API will return YAML-HTML, which the browser can display. In other words, you can play with the API using just your browser and see results in a human-readable form. Here is an example. This is a good way to try out the various GET calls, even if you can't use it for POST or PUT. For that, the Firefox "RESTClient" addon is very useful.
Data Formats
Aside from the above-mentioned "browsing" facility, the REST API only supports JSON input, and either JSON and JSONP output. So objects sent and received must be in JSON format.
On every request, you must set both the "Accept" and "Content-Type" HTTP headers to the MIME type of the data format you are using to communicate with the API. Content-Type tells the API how to interpret your request, and Accept tells it how you want your data back. "Content-Type" must be "application/json". "Accept" can be either that, or "application/javascript" for JSONP - add a "callback" parameter to name your callback.
Authentication
The API and the proxy support anonymous access as much as the target Bugzilla does.
Note: The above-mentioned instance of the API is available over HTTPS and accesses bugzilla.mozilla.org over HTTPS. (The cert is from GeoTrust's Equifax root, which should be trusted by all current browsers.) So login information should be safe in transit.
There are two ways to authenticate.
Username and Password Auth
Pass e.g.:
username=fred@bedrock.com&password=ilovewilma
as query parameters on any request.
Cookie Auth
If you have access to some existing Bugzilla login cookies for the user, you can also authenticate using that. You pass the data as URL parameters rather than as Cookie headers to prevent cross-site request forgery (XSRF).
Note that the cookies are HTTPOnly and so you can't access this info from unprivileged in-page JavaScript. However, if you have chrome privileges, you can ask the cookie service.
userid=1234&cookie=mG4J9OT4B6
The "userid" parameter is a numeric user ID, the contents of the "Bugzilla_login" cookie. The "cookie" parameter is a random string, the contents of the "Bugzilla_logincookie" cookie.
Field Control
For those calls which return significant data (i.e. GETs), each call returns a number of fields by default. Often, it's all available fields, but for some calls (e.g. bug lists, individual bugs) it's fewer than that. You can control exactly what fields you get using the include_field and exclude_field parameters. These take a comma-separated list of field names, and work as follows:
- If you specify some include_fields, you select just those fields
- If one of your field names is "_default" (note underscore), you select the default fields plus any others you specify
- If one of your field names is "_all" (note underscore), you select all available fields, regardless of whether you specify any others as well
- After that, if you have specified exclude_fields, they are removed before the data is returned.
Errors
If methods are not successful for whatever reason, they will return an Error. You should test every API return to see if it is an error ("error" member set to a true value).
The "code" field on an Error, if present, will give an error code from this list. The other member variables of the object are not stable, and should not be relied upon. The html_page, in particular, is only there so you can read it manually for a better idea of what the error was, and ask for the API to support it properly.
Your Own Installation
If you want to install the API proxy on your own machine for your own Bugzilla, you will need:
- the latest stable 3.4.x or 3.6.x release of Bugzilla (many features will not work on 3.2); and
- to be using UTF-8 (this is the default on new installations).
- To have the necessary optional modules for XML-RPC (e.g. Test::Taint).
Then, install a copy of the API software - it does not have to be on the same machine. See the INSTALL file in the repository for some installation hints; feel free to send me tips from your experience.
You can get the code from the Mozilla Mercurial (hg) repository:
hg clone http://hg.mozilla.org/webtools/bzapi bzapi
Patches
Even the latest stable release of Bugzilla requires a little modification to work properly with the BzAPI. Unfortunately, it is not possible to support all the necessary functionality without some changes to Bugzilla itself, which are considered either unnecessary or too intrusive for a stable release series.
- Make legacy XML interface supply more data (flags, etc.) - for 3.4 only; you'll need patch version 8a.
- JSON template for config.cgi - for 3.4 and 3.6; you'll need the original patch v.1 and then the most recent config.json.tmpl, which is attached to a different bug. (Note: updated 14/09/2010)