API Not Returning All Data

michael's Avatar

michael

02 Jul, 2009 09:00 AM

For an internal app, I pull down all our tickets using the API every 5 minutes. Up until around tuesday, this worked perfectly - then the numbers reported by the API dropped dramatically.

A search for state:resolved shows 251 tickets, but the API is only reporting 39.

I get the number of tickets using the following code. $c is just a cURL wrapper, which is definitely bug free.

<?php

$apiKey = 'API_KEY';

$c = new cURL();
$c->setPostType('application/xml');
$c->addPersistantHeader("X-LighthouseToken", $apiKey);

function listTickets($projID,$getParams=array()){
    if (!empty($getParams)){
        foreach ($getParams as $key => $val){
            $qString .= '&'.$key.'='.urlencode($val).'';
        }
        $qString = '?'.substr($qString, 1);
    }

    global $c;
    $res = $c->get("projects/".$projID."/tickets.xml".$qString);
    return @simplexml_load_string(trim($res['response']));
}

$projects = array(95412, 31342, 85412, 35312, 43432, 70532, 83432, 42432, 55342);

$total = 0;
foreach ($projects as $id){ 
    $xml = listTickets($id, array("q" => "state:resolved"));
    $total += count($xml->ticket);
}

echo $total; // 39

?>

As you can see, it loops through all of our projects (ID's supplied by the API usually, but put in an array for testing) and looks for all tickets with state:resolved. It then counts the number of $xml->ticket returned, as $xml->ticket is the data for one single ticket.

  1. 1 Posted by Rick on 04 Jul, 2009 05:37 AM

    Rick's Avatar

    The results have always been paginated. If a search yields 200 results, the API call will only grab 30 of them. Calling the API every 5 minutes like this isn't good at all, perhaps I can add an API call to show the status of a ticket bin so you can get this much easier.

  2. 2 Posted by michael on 06 Jul, 2009 08:59 AM

    michael's Avatar

    Hey Rick,
    Calling the API like this isn't really the best solution, but it's the only one we could come up with. If you have any suggestions, I'd love to hear them.

    We currently have a display in the office which lists all of our project states, and all of our users. For each state, it lists the number of tickets in that state, and for the user, it lists all open tickets for the user.

    If you could add a search summary API call, that'd be great. e.g. I make a call for the summary with state:resolved and it just returns the number of tickets in that state. For users, I'd search for a user and it would return how many open tickets, and how many closed tickets. This would preferably be across all projects, but if that's a bit tricky I could call the api once for each project and state/user combination.

  3. 3 Posted by Rick on 06 Jul, 2009 04:22 PM

    Rick's Avatar

    I'll see about sneaking this in sometime this week. Anything to get you from pounding the site like you have been lately :)

  4. 4 Posted by michael on 15 Jul, 2009 09:48 AM

    michael's Avatar

    Just wondering if there's any progress on this?
    M

  5. 5 Posted by Rick on 11 Aug, 2009 06:35 PM

    Rick's Avatar

    Ah no, things have been super busy, I'll get it in as soon as I can.

  6. 6 Posted by System on 13 Aug, 2009 05:15 AM

    System's Avatar

    A Lighthouse ticket was created for this discussion

  7. Nicole closed this discussion on 20 Jan, 2010 08:15 AM.

Discussions are closed to public comments.
If you need help with Lighthouse please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac