1

Using the Element API is there a way to get entries by dateUpdated OR dateCreated within the last whatever time, say day?

Or a way to get the entry IDs for both of those criteria then do a query based on just the IDs from both results?

I want to get any entry that was created or updated within the last day using the API but can't quite get it.

2

If you want the latest of both, unless I'm missing something, you should just be able to query on dateUpdated.

When you create an entry the first time, its dateUpdated gets set to the same date as the dateCreated... So if you query your entries on dateUpdated only, you will get all entries created + updated in your time frame I guess.

As far as code goes, this should do it:

return [
    'endpoints' => [
        'entries.json' => function() {
            $timeframe = (new \DateTime('1 day ago'))->format(\DateTime::ATOM);
            return [
                'elementType' => Entry::class,
                'criteria' => [
                    'section' => 'entries',
                    'dateUpdated' => '>=' . $timeframe,
                ],
                'transformer' => function(Entry $entry) {
                    return [
                        'title' => $entry->title,
                        'url' => $entry->url,
                    ];
                },
            ];
        },
    ]
];
| improve this answer | |
  • I didn't even think of that. That will probably work fine for my situation then. – Erik Jan 15 '19 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.