Using Element API, how do I get the next entry? return [
    'endpoints' =&gt; [

        'journal/&lt;entryId:\d+&gt;.json' =&gt; function($entryId) {
            return [
                'elementType' =&gt; 'Entry',
                'criteria' =&gt; ['id' =&gt; $entryId, 'section'=&gt;'journal'],
                'first' =&gt; true,
                'transformer' =&gt; function(EntryModel $entry) {
                    $nextEntry = $entry-&gt;getNextSibling();
                    // also tried getNext()

                    $upNext = [];
                    $upNext["title"] = $nextEntry-&gt;title;
                    // errs out here ...
                }
            ];
        }
    ]
];


I feel like I'm missing something obvious, but how do I get the next sibling of an entry using Element API?  Would it be easier/better to pass both the current entry ID and the next entry ID (which I have available) into the criteria to make it easier to grab?

Thanks!
Depends on what you mean by “next”.

If the entry is within a Structure section and you want whatever entry is positioned after it, you’d use getNextSibling().



$nextSibling = $entry-&gt;getNextSibling();


Otherwise you want getNext(). But you need to keep in mind that which entry is next can vary in infinite ways, so you really need to supply that $criteria argument here.

The point of the $criteria argument is to define a collection of entries in a specific order, in which $entry is one of them, and Craft uses that to determine which entries come immediately before and after it.

Your example code shows that you are returning Journal entries, so I’ll assume that you want $nextEntry to be the journal entry that was written after $entry – so the entries should be sorted in chronological order. If that’s the case, here’s the code you should use:

$nextEntry = $entry-&gt;getNext([
    'section' =&gt; 'journal',
    'order' =&gt; 'postDate asc'
]);


As far as what you can pass into that argument, all of the craft.entries parameters are fair game here, with the exact same value syntax. Just keep in mind that it’s PHP code and not Twig, so instead of something like:

.postDate('&lt;= 2013-06-04')


it would be:

'postDate' =&gt; '&lt;= 2013-06-04',


You can also pass in an actual ElementCriteriaModel object, with its values set ahead of time:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'journal';
$criteria-&gt;postDate = '&lt;= 2013-06-04';
$criteria-&gt;order = 'postDate asc';

$nextEntry = $entry-&gt;getNext($criteria);