Answers.Body: <p>Same as you would access it from a Twig <a href="https://craftcms.com/docs/categories-fields#templating" rel="nofollow">template</a>.  If you're positive there will always be one category selected, then this would work:</p>
  
  <pre><code>'transformer' =&gt; function(EntryModel $entry) {
      return [
          'category' =&gt; (string)$entry-&gt;categoryHandle[0],
      ];
  },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-20T16:12:33.047Z
Answers.Text: yeah, I'd thought I could have done that but nothing comes from it.
Answers.UserDisplayName: Steven Grant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-20T18:52:36.723Z
Answers.Text: Are you sure you have the correct `$entry`? What do you get if you dump `$entry->categoryHandle[0]` from a normal Twig template?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-20T19:35:10.577Z
Answers.Text: Should have clarified, this is for all jobs, not a single entry endpoint. I found that ```'category' => (string) $entry->jobCategory[0],``` works though
Answers.UserDisplayName: Steven Grant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-20T21:53:23.277Z
Answers.Text: Weird... CategoryModel's `__toString()` magic method should be getting called there.  Regardless, I'll update my answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-20T02:48:35.460Z
Answers.LastActivityDate: 2015-12-20T21:53:34.910Z
Answers.LastEditDate: 2015-12-20T21:53:34.910Z
Answers.UserDisplayName: Brad Bell
Body: <p>The category count is only ever 1 and I need to output the name of the category the entry belongs to.</p>
  
  <p>Would there need to be a cross-over between the EntryModel and CategoryModel?</p>
  
  <pre><code>'transformer' =&gt; function(EntryModel $entry) {
                  return [
                      'title' =&gt; $entry-&gt;title,
                      'url' =&gt; $entry-&gt;url,
                      'jsonUrl' =&gt; UrlHelper::getUrl("jobs/{$entry-&gt;id}.json"),
                      'postDate' =&gt; $entry-&gt;postDate-&gt;getTimestamp() * 1000,
                      'id' =&gt; $entry-&gt;id,
                      'jobOverview' =&gt; (string) $entry-&gt;jobOverview,
                      'category' =&gt; $entry-&gt;jobCategory[0],
                  ];
              },
  </code></pre>
  
Tags: <json><plugin-elementapi>
Title: How do I access the category of an entry with Element API?
ThreadText: # How do I access the category of an entry with Element API?
  
  (Asked by: username_0 on 2015-12-19)
  
  The category count is only ever 1 and I need to output the name of the category the entry belongs to.
  
  Would there need to be a cross-over between the EntryModel and CategoryModel?
  
  ```
  'transformer' => function(EntryModel $entry) {
                  return [
                      'title' => $entry->title,
                      'url' => $entry->url,
                      'jsonUrl' => UrlHelper::getUrl("jobs/{$entry->id}.json"),
                      'postDate' => $entry->postDate->getTimestamp() * 1000,
                      'id' => $entry->id,
                      'jobOverview' => (string) $entry->jobOverview,
                      'category' => $entry->jobCategory[0],
                  ];
              },
  
  ```
  
  **Tags:** json, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-20. Score: 3 | Accepted answer
  
  Same as you would access it from a Twig [template](https://craftcms.com/docs/categories-fields#templating). If you're positive there will always be one category selected, then this would work:
  
  ```
  'transformer' => function(EntryModel $entry) {
      return [
          'category' => (string)$entry->categoryHandle[0],
      ];
  },
  
  ```
  
  > **Comments:**
  > **username_0**: yeah, I'd thought I could have done that but nothing comes from it.  
  > **username_1**: Are you sure you have the correct `$entry`? What do you get if you dump `$entry->categoryHandle[0]` from a normal Twig template?  
  > **username_0**: Should have clarified, this is for all jobs, not a single entry endpoint. I found that ```'category' => (string) $entry->jobCategory[0],``` works though  
  > **username_1**: Weird... CategoryModel's `__toString()` magic method should be getting called there.  Regardless, I'll update my answer.  
  
  ---
  
  