How do I query data using the Element API Plugin based on a custom field? I have a channel called "offers".

My Offers channel contains a field called "Users".

The Users field is the "users" field type. It allows me to select 1 or more users that the Offer is for.

I want to get JSON output for this data based on the "Users" name. 

'users/&lt;username:{handle}&gt;/offers.json' =&gt; function($username) {
            return [
                'elementType' =&gt; 'Entry',
                'criteria' =&gt; ['section' =&gt; 'specialOffers', 'relatedTo' =&gt; $username],
            'transformer' =&gt; function(EntryModel $entry) {
                return [
                    'title' =&gt; $entry-&gt;title,
                    'category' =&gt; $entry-&gt;category-&gt;label,

                ];
              },
            ];
        },
You’re close. But the relatedTo param can’t just be set to some username. It has to either be an element ID or an actual element model (more specifically, a user ID or UserModel in this case).

'users/&lt;username:{handle}&gt;/offers.json' =&gt; function($username) {
    // Get the actual user model
    $criteria = craft()-&gt;elements-&gt;getCriteria('User');
    $criteria-&gt;username = $username;
    $user = $criteria-&gt;first();

    // If there was no user, return no results
    if (!$user) {
        return [
            'elementType' =&gt; 'Entry',
            'criteria' =&gt; ['id' =&gt; false],
        ];
    }

    return [
        'elementType' =&gt; 'Entry',
        'criteria' =&gt; [
            'section' =&gt; 'specialOffers',
            'relatedTo' =&gt; ['targetElement' =&gt; $user]
        ],
        // ...
    ];
},