multiple if statements "forced" by database query result & external api response
If you don't want to repeat yourself (DRY) then consider using multiple methods, and set properties ($this->collection) and/or pass parameters, as necessary. If you are finding yourself nesting if statements inside a method, it is a good indication that you should be using multiple methods.

For example, for your method, it looks like you could cut the database check into their own method.

If you have a return, then there is no need for an else statement :-) 

if($a){
  return;
}
// no need for else


There is no point in setting a variable $json and echo it, just echo it as you did most of the time, but not all.

It looks as though you could break the rest response into it's own method for example with the if count > 0 return true or false to determine the action.

private function method($results){
    if (count(($results)) &gt; 0) {
        echo Zend_Json::encode($result);
        return true;
    }
    return false;
}


Check out this video "Your code sucks, let's fix it - By Rafael Dohms" to help with understanding the above.
https://www.youtube.com/watch?v=GtB5DAfOWMQ

I hope this is helpful!