<p>I figured it out. Turned out I had entered the criteria incorrectly, as channel instead of section.</p>

<pre><code>'criteria' =&gt; ['section' =&gt; 'movies'],
</code></pre>

<p>not</p>

<pre><code>'criteria' =&gt; ['channel' =&gt; 'movies'],
</code></pre>

CC BY-SA 3.0
2015-11-30T07:12:03.137Z
2015-11-30T07:12:03.137Z
divinemonkey
<p>Hopefully my titles makes some sense but I will try to elaborate.</p>

<p>I have a Channel entry called Movies that I am using the Element API to turn into JSON. There is a field inside that called Movie Genre which is an Entry type field.</p>

<p>When I create this transformer:</p>

<pre><code>'transformer' =&gt; function(EntryModel $movie) {

                return [
                    'name' =&gt; $movie-&gt;title,
                    'genres' =&gt; $movie-&gt;movieGenre[0]-&gt;title
                ];
            },
</code></pre>

<p>This is the JSON I get now, which looks to me like it is gathering all entries, not just the ones inside the channel.</p>

<blockquote>
  <p>{"data":[{"name":"Harry Potter and The Order of the
  Phoenix","genres":"Fantasy"},{"name":"Jurassic
  World","genres":"Science
  Fiction"},{"name":"Romance","genres":null},{"name":"Science
  Fiction","genres":null},{"name":"Comedy","genres":null},
  {"name":"Fantasy","genres":null},{"name":"Guardians
  of the Galaxy","genres":"Action"},{"name":"Horror","genres":null},
  {"name":"Action","genres":null},{"name":"Home","genres":null},
  {"name":"Thirteen Ghosts","genres":"Horror"},
  {"name":"Movies","genres":null},{"name":"Genres","genres":null}],"meta":
  {"pagination":
  {"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}</p>
</blockquote>

<p>What I need to happen is only the Movies get returned as an item in the JSON and the movieGenre entry type not as its own item.</p>

<p>This is the desired JSON outcome.</p>

<blockquote>
  <p>{"data":[{"name":"Harry Potter and The Order of the
  Phoenix","genres":"Fantasy"},{"name":"Jurassic
  World","genres":"Science Fiction"},{"name":"Guardians of the
  Galaxy","genres":"Action"},{"name":"Thirteen
  Ghosts","genres":"Horror"}],"meta":{"pagination":{"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}</p>
</blockquote>

CC BY-SA 3.0
2015-11-29T16:46:39.177Z
I'm not sure I'm follow... can you edit the original question to show what your desired JSON output would be?
Brad Bell
CC BY-SA 3.0
2015-11-30T06:57:27.397Z
Updated. Hopefully I have used my words better now. Thanks.
divinemonkey
<entry-type><channels><json><plugin-elementapi>
Element API: Entry field inside a Channel entry being passed into JSON file
# Element API: Entry field inside a Channel entry being passed into JSON file

(Asked by: username_0 on 2015-11-29)

Hopefully my titles makes some sense but I will try to elaborate.
I have a Channel entry called Movies that I am using the Element API to turn into JSON. There is a field inside that called Movie Genre which is an Entry type field.
When I create this transformer:
'transformer' => function(EntryModel $movie) {

                return [
                    'name' => $movie->title,
                    'genres' => $movie->movieGenre[0]->title
                ];
            },

This is the JSON I get now, which looks to me like it is gathering all entries, not just the ones inside the channel.

{"data":[{"name":"Harry Potter and The Order of the
  Phoenix","genres":"Fantasy"},{"name":"Jurassic
  World","genres":"Science
  Fiction"},{"name":"Romance","genres":null},{"name":"Science
  Fiction","genres":null},{"name":"Comedy","genres":null},
  {"name":"Fantasy","genres":null},{"name":"Guardians
  of the Galaxy","genres":"Action"},{"name":"Horror","genres":null},
  {"name":"Action","genres":null},{"name":"Home","genres":null},
  {"name":"Thirteen Ghosts","genres":"Horror"},
  {"name":"Movies","genres":null},{"name":"Genres","genres":null}],"meta":
  {"pagination":
  {"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}

What I need to happen is only the Movies get returned as an item in the JSON and the movieGenre entry type not as its own item.
This is the desired JSON outcome.

{"data":[{"name":"Harry Potter and The Order of the
  Phoenix","genres":"Fantasy"},{"name":"Jurassic
  World","genres":"Science Fiction"},{"name":"Guardians of the
  Galaxy","genres":"Action"},{"name":"Thirteen
  Ghosts","genres":"Horror"}],"meta":{"pagination":{"total":13,"count":13,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}

**Tags:** entry-type, channels, json, plugin-elementapi
> **Comments:**
> **username_1**: I'm not sure I'm follow... can you edit the original question to show what your desired JSON output would be?  
> **username_0**: Updated. Hopefully I have used my words better now. Thanks.  

---

## 1 answers

### Answer by username_0 on 2015-11-30. Score: 1 | Accepted answer

I figured it out. Turned out I had entered the criteria incorrectly, as channel instead of section.
'criteria' => ['section' => 'movies'],

not
'criteria' => ['channel' => 'movies'],


---

