Bugzilla:BzAPI:HowTo: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
==Example==
==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.
Here is a simple example in JavaScript 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 handleResponse(response)
{
{
   var output = "";
   var output = "";
   var bugs = response.bugs;
  var json = JSON.parse(response);
   var bugs = json.bugs;


   for (var i = 0; i < bugs.length; i++) {
   for (var i = 0; i < bugs.length; i++) {
     output += bugs[i].id + " " + bugs[i].summary + "\n";
     output += bugs[i].id + ": " + bugs[i].summary + "\n";
   }
   }


Line 19: Line 20:


function progressListener() {
function progressListener() {
   if(this.readyState == 4 && this.status == 200) {
   if (this.readyState == 4 && this.status == 200) {
     var json = JSON.parse(this.responseText);
     handleResponse(this.responseText);
    doSomething(json);
   }
   }
}
}


function getNewBugs()
function getMyActiveBugs(bugzillaLogin)
{
{
   var bugzillaLogin = "gerv@mozilla.org";
   var apiURL = "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";
 
   var client = new XMLHttpRequest();
   var client = new XMLHttpRequest();
   client.onreadystatechange = progressListener;
   client.onreadystatechange = progressListener;
   client.open("GET",
   client.open("GET", apiURL);
              "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('Accept',      'application/json');
   client.setRequestHeader('Content-Type', 'application/json');
   client.setRequestHeader('Content-Type', 'application/json');
Line 41: Line 40:
}
}


getNewBugs();
getMyActiveBugs("gerv@mozilla.org");
</pre>
</pre>


Account confirmers, Anti-spam team, Confirmed users, Bureaucrats and Sysops emeriti
4,925

edits

Navigation menu