Answers.Body: <p>Completely untested, but something like this should work:</p>
  
  <pre><code>'dealers/&lt;username:(.*)&gt;.json' =&gt; function($username) {
      $author = craft()-&gt;users-&gt;getUserByUsernameOrEmail($username);
  
      return [
          'elementType' =&gt; 'Entry',
          'criteria' =&gt; [
              'section' =&gt; 'listings',
              'authorId' =&gt; $author-&gt;id
          ],
          'paginate' =&gt; false,
          'transformer' =&gt; function(EntryModel $entry) {
              ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-22T13:51:06.800Z
Answers.Text: While it didn't give me an error, this did not work. It just lists all entries within the 'listings' section, not filtering by username.
Answers.UserDisplayName: Noah Yamen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-22T14:59:14.353Z
Answers.Text: Additional note: I do have a working feed that does filter listings via authorID. But that's by using the author ID in the feed URL. In this feed's case, it has to have the username of the user. Is there a way to get the ID of a user via their username, and then pass it to " 'authorId' => $authorId"?
Answers.UserDisplayName: Noah Yamen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-24T07:22:16.677Z
Answers.Text: Just did a test of this and it works for me?  Are you testing with a username you know that actually exists?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-24T15:42:29.097Z
Answers.Text: Yes, currently since the site is only in development there are only 3 existing users. And I know for a fact that I'm using the exact username in every instance.
Answers.UserDisplayName: Noah Yamen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-24T15:58:05.887Z
Answers.Text: The issue for me seems to be with the `'author' => $author` criteria. Because `craft()->users->getUserByUsernameOrEmail($username);` is definitely working, it's successfully recognizing an existing user. But the author criteria doesn't seem to work in conjunction with the EntryModel. Only authorId works for me here. I've also tried using `'author' => 'noahyamen'` (my username in craft) and it still doesn't filter the results. (And I know for a fact the entries have different authors other than me).
Answers.UserDisplayName: Noah Yamen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-17T21:06:37.997Z
Answers.Text: Pretty sure you need to use `'authorId' => $author->id` in your criteria, not `'author' => $author`.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T22:47:51.900Z
Answers.LastActivityDate: 2017-09-18T03:34:43.343Z
Answers.LastEditDate: 2017-09-18T03:34:43.343Z
Answers.UserDisplayName: Brad Bell
Body: <p>Struggling to get this feed work with Element API. I'm trying to return all entries created by a specific username. I've tried several different methods, but none of them work. </p>
  
  <p>Here is the latest version of what I've tried:</p>
  
  <pre><code>'dealers/&lt;username:{username}&gt;.json' =&gt; function($username) {
    return [
      'elementType' =&gt; 'Entry',
      'criteria' =&gt; [
        'section' =&gt; 'listings',
        'username' =&gt; $username
      ],
      'paginate' =&gt; false,
      'transformer' =&gt; function(EntryModel $entry) {
        ...
  </code></pre>
  
Tags: <entries><plugin-elementapi>
Title: Element API: how can I return entries via username?
ThreadText: # Element API: how can I return entries via username?
  
  (Asked by: username_0 on 2017-05-19)
  
  Struggling to get this feed work with Element API. I'm trying to return all entries created by a specific username. I've tried several different methods, but none of them work.
  
  Here is the latest version of what I've tried:
  
  ```
  'dealers/<username:{username}>.json' => function($username) {
    return [
      'elementType' => 'Entry',
      'criteria' => [
        'section' => 'listings',
        'username' => $username
      ],
      'paginate' => false,
      'transformer' => function(EntryModel $entry) {
        ...
  
  ```
  
  **Tags:** entries, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-19. Score: 1
  
  Completely untested, but something like this should work:
  
  ```
  'dealers/<username:(.*)>.json' => function($username) {
      $author = craft()->users->getUserByUsernameOrEmail($username);
  
      return [
          'elementType' => 'Entry',
          'criteria' => [
              'section' => 'listings',
              'authorId' => $author->id
          ],
          'paginate' => false,
          'transformer' => function(EntryModel $entry) {
              ...
  
  ```
  
  > **Comments:**
  > **username_0**: While it didn't give me an error, this did not work. It just lists all entries within the 'listings' section, not filtering by username.  
  > **username_0**: Additional note: I do have a working feed that does filter listings via authorID. But that's by using the author ID in the feed URL. In this feed's case, it has to have the username of the user. Is there a way to get the ID of a user via their username, and then pass it to " 'authorId' => $authorId"?  
  > **username_1**: Just did a test of this and it works for me?  Are you testing with a username you know that actually exists?  
  > **username_0**: Yes, currently since the site is only in development there are only 3 existing users. And I know for a fact that I'm using the exact username in every instance.  
  > **username_0**: The issue for me seems to be with the `'author' => $author` criteria. Because `craft()->users->getUserByUsernameOrEmail($username);` is definitely working, it's successfully recognizing an existing user. But the author criteria doesn't seem to work in conjunction with the EntryModel. Only authorId works for me here. I've also tried using `'author' => 'username_0'` (my username in craft) and it still doesn't filter the results. (And I know for a fact the entries have different authors other than me).  
  > **username_2**: Pretty sure you need to use `'authorId' => $author->id` in your criteria, not `'author' => $author`.  
  
  ---
  
  