Accessing global sets from Element API Is there an easy way to access global sets from an Element API endpoint, so its content can be included in the JSON response?
Since Global Sets are elements just like entries, users, etc., you can create API endpoints that are all about them:



'globals/&lt;handle:\w+&gt;' =&gt; function($handle) {
    return [
        'elementType' =&gt; 'GlobalSet',
        'criteria' =&gt; ['handle' =&gt; $handle],
        'first' =&gt; true,
        'transformer' =&gt; function(\Craft\GlobalSetModel $globalSet) {
            return [
                'foo' =&gt; $globalSet-&gt;foo,
                'bar' =&gt; $globalSet-&gt;bar,
            ];
        }
    ];
}


You can also manually query for Global Sets, to include their data in an endpoint that’s tied to another element type:

'my/other/endpoint' =&gt; [
    'elementType' =&gt; 'Entry',
    // ...
    'transformer' =&gt; function(\Craft\EntryModel $globalSet) {
        // ...

        // Fetch a global set
        $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::GlobalSet);
        $criteria-&gt;handle = 'myHandle';
        $myGlobalSet = $criteria-&gt;first();

        // Include the global set content in the response data
        return [
            // ...
            'foo' =&gt; $myGlobalSet-&gt;foo,
            'bar' =&gt; $myGlobalSet-&gt;bar,
        ]
    }
]


Craft also provides a couple methods for fetching Global Sets by ID or handle, so if that happens to be exactly what you need, feel free to use those:


craft()->globals->getSetById()
craft()->globals->getSetByHandle()