By default the Element API plugin all endpoints in a data object like this:

{ "data": [ { "key" : "value", "key2": "value2" } ]}

But i don't want to wrap this in the data object but like this:

{ "key" : "value", "key2": "value2" }

Use the config setting 'first' => true and wrap the endpoint in a function

like this:

'api/link' => function() {
    return [
        'elementType' => 'Entry',
        'first' => true,
        'criteria' => ['section' => 'mysecton'],
        'paginate' => false,
        'transformer' => function(EntryModel $entry) {
            return $something;

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.