Answers.Body: <p>I ended up doing it like this:</p>
  
  <pre><code>'api/featured-apps.json' =&gt; [
    'elementType' =&gt; 'Entry',
    'criteria' =&gt; [
      'section' =&gt; 'apps',
      'appFeatured' =&gt; '1',
    ],
    'transformer' =&gt; function (EntryModel $entry) { 
      $logos = [];
      foreach ($entry-&gt;appLogo as $image) {
        $logos[] = $image-&gt;url;
      }
  
      $videos = [];
      foreach ($entry-&gt;appVideo as $video) {
        $videos[] = $video-&gt;url;
      }
  
      return [
        'title' =&gt; $entry-&gt;title,
        'logo' =&gt; $logos,
        'video' =&gt; $videos,
      ];
    }
  ],
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T17:01:04.177Z
Answers.LastActivityDate: 2017-04-04T17:01:04.177Z
Answers.UserDisplayName: Molly Harper
Answers.Body: <p>Assuming both <code>appLogo</code> and <code>appVideo</code> are Asset fields, they will always return an array, even if there is only one asset selected.</p>
  
  <pre><code>'logo' =&gt; $entry-&gt;appLogo-&gt;first(),
  'video' =&gt; $entry-&gt;appVideo-&gt;first(),
  </code></pre>
  
  <p>Should do what you're looking for.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-04T16:59:55.673Z
Answers.Text: That didn't work
Answers.UserDisplayName: Molly Harper
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-02T03:42:47.457Z
Answers.LastActivityDate: 2017-04-02T03:42:47.457Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm using the <a href="https://github.com/craftcms/element-api" rel="nofollow noreferrer">Element API</a> and would like to return content based on it's handle. The two handles I am trying to return are called appLogo and appVideo:</p>
  
  <pre><code>'api/featured-apps.json' =&gt; [
    'elementType' =&gt; 'Entry',
    'criteria' =&gt; [
      'section' =&gt; 'apps',
      'appFeatured' =&gt; '1',
    ],
    'transformer' =&gt; function (EntryModel $entry) {
      return [
        'title' =&gt; $entry-&gt;title,
        'logo' =&gt; $entry-&gt;appLogo,
        'video' =&gt; $entry-&gt;appVideo,
      ];
    }
  ],
  </code></pre>
  
  <p>This does not work, do I need to access images/videos in a different way? Ideally, I'd like the relative path returned for both logo and video.</p>
  
Tags: <plugin-elementapi>
Title: Access handle value using element API
ThreadText: # Access handle value using element API
  
  (Asked by: username_0 on 2017-04-01)
  
  I'm using the [Element API](https://github.com/craftcms/element-api) and would like to return content based on it's handle. The two handles I am trying to return are called appLogo and appVideo:
  
  ```
  'api/featured-apps.json' => [
    'elementType' => 'Entry',
    'criteria' => [
      'section' => 'apps',
      'appFeatured' => '1',
    ],
    'transformer' => function (EntryModel $entry) {
      return [
        'title' => $entry->title,
        'logo' => $entry->appLogo,
        'video' => $entry->appVideo,
      ];
    }
  ],
  
  ```
  
  This does not work, do I need to access images/videos in a different way? Ideally, I'd like the relative path returned for both logo and video.
  
  **Tags:** plugin-elementapi
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-04-04. Score: 1 | Accepted answer
  
  I ended up doing it like this:
  
  ```
  'api/featured-apps.json' => [
    'elementType' => 'Entry',
    'criteria' => [
      'section' => 'apps',
      'appFeatured' => '1',
    ],
    'transformer' => function (EntryModel $entry) { 
      $logos = [];
      foreach ($entry->appLogo as $image) {
        $logos[] = $image->url;
      }
  
      $videos = [];
      foreach ($entry->appVideo as $video) {
        $videos[] = $video->url;
      }
  
      return [
        'title' => $entry->title,
        'logo' => $logos,
        'video' => $videos,
      ];
    }
  ],
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2017-04-02. Score: 0
  
  Assuming both `appLogo` and `appVideo` are Asset fields, they will always return an array, even if there is only one asset selected.
  
  ```
  'logo' => $entry->appLogo->first(),
  'video' => $entry->appVideo->first(),
  
  ```
  
  Should do what you're looking for.
  
  > **Comments:**
  > **username_0**: That didn't work  
  
  ---
  
  