Bugzilla:BzAPI:HowTo: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This page is a repository for tips, tricks, ideas, code samples etc. for the Bugzilla REST API. | This page is a repository for tips, tricks, ideas, code samples etc. for the Bugzilla REST API. | ||
==Example== | ==Example== | ||
Here is a simple example using XHR. It will return bugs that were changed in the last day | Here is a simple example using XHR. It will return any bugs that you have ever commented on, that were also changed in the last day. | ||
<pre> | <pre> | ||
function doSomething(response) | |||
function | |||
{ | { | ||
var | var output = ""; | ||
var bugs = response.bugs; | |||
var bugs = | |||
for (var i = 0; i < | for (var i = 0; i < bugs.length; i++) { | ||
output += bugs[i].id + " " + bugs[i].summary + "\n"; | |||
} | } | ||
alert( | alert(output); | ||
} | } | ||
function | function progressListener() { | ||
if(this.readyState == 4 && this.status == 200) { | |||
var json = JSON.parse(this.responseText); | |||
doSomething(json); | |||
} | |||
} | } | ||
function getNewBugs() | function getNewBugs() | ||
{ | { | ||
var | var bugzillaLogin = "gerv@mozilla.org"; | ||
var client = new XMLHttpRequest(); | var client = new XMLHttpRequest(); | ||
client.onreadystatechange = | client.onreadystatechange = progressListener; | ||
client.open("GET", | client.open("GET", | ||
"https://api-dev.bugzilla.mozilla.org/0.2/bug?email1=" + | "https://api-dev.bugzilla.mozilla.org/0.2/bug?email1=" + | ||
bugzillaLogin + | |||
"&email1_type=equals_any&email1_comment_author=1" + | "&email1_type=equals_any&email1_comment_author=1" + | ||
"& | "&changed_after=1d&changed_before=Now"); | ||
client.setRequestHeader('Accept', 'application/json'); | |||
/ | client.setRequestHeader('Content-Type', 'application/json'); | ||
client.setRequestHeader(' | |||
client.send(); | client.send(); | ||
} | } | ||
getNewBugs(); | |||
</pre> | |||
==Requests== | |||
There is no API equivalent of request.cgi, but you can get the same information via the standard search. Use the Boolean Charts, and the fields '''flag.requestee''', '''flag.setter''', '''product''', '''component''' and '''flag''' to replicate the searches that request.cgi give you, and of course you can add in any other parameters you want to search on. | |||
Flags are not returned in search results, so when you get the results back, make an individual request for each bug, in parallel if you like, to give you a full bug object including the flags. (There is currently no way of getting multiple full bug objects in a single request; if there is demand, we may add this to the API as a special case for searching on bug IDs only.) You can then take this list and filter or present it in whatever way you choose. And because you have the bug objects, you can change the flag fields and submit them back in order to update things. |
Revision as of 20:47, 16 November 2009
This page is a repository for tips, tricks, ideas, code samples etc. for the Bugzilla REST API.
Example
Here is a simple example using XHR. It will return any bugs that you have ever commented on, that were also changed in the last day.
function doSomething(response) { var output = ""; var bugs = response.bugs; for (var i = 0; i < bugs.length; i++) { output += bugs[i].id + " " + bugs[i].summary + "\n"; } alert(output); } function progressListener() { if(this.readyState == 4 && this.status == 200) { var json = JSON.parse(this.responseText); doSomething(json); } } function getNewBugs() { var bugzillaLogin = "gerv@mozilla.org"; var client = new XMLHttpRequest(); client.onreadystatechange = progressListener; client.open("GET", "https://api-dev.bugzilla.mozilla.org/0.2/bug?email1=" + bugzillaLogin + "&email1_type=equals_any&email1_comment_author=1" + "&changed_after=1d&changed_before=Now"); client.setRequestHeader('Accept', 'application/json'); client.setRequestHeader('Content-Type', 'application/json'); client.send(); } getNewBugs();
Requests
There is no API equivalent of request.cgi, but you can get the same information via the standard search. Use the Boolean Charts, and the fields flag.requestee, flag.setter, product, component and flag to replicate the searches that request.cgi give you, and of course you can add in any other parameters you want to search on.
Flags are not returned in search results, so when you get the results back, make an individual request for each bug, in parallel if you like, to give you a full bug object including the flags. (There is currently no way of getting multiple full bug objects in a single request; if there is demand, we may add this to the API as a special case for searching on bug IDs only.) You can then take this list and filter or present it in whatever way you choose. And because you have the bug objects, you can change the flag fields and submit them back in order to update things.