Answers.Body: <p><strong>Update:</strong></p>
  
  <p>Looks like changing the <code>'data'</code> key is a bit more difficult I suspected.  We just released <a href="https://github.com/craftcms/element-api/releases/tag/1.3.0" rel="nofollow noreferrer">Element API 1.3.0</a> that exposes the internal <code>$resourceKey</code> necessary to change that value.</p>
  
  <p>In your <code>elementapi.php</code> config file, something like this should work:</p>
  
  <p><strong>UPDATE:</strong> This is the final code that I used, and it works perfectly.</p>
  
  <pre><code>return [
      'defaults' =&gt; [
          'resourceKey' =&gt; 'manifest'
      ],
  
      'endpoints' =&gt; [
          'assets/data/assets.json' =&gt; [
              'paginate' =&gt; false,
              'elementType' =&gt; ElementType::Asset,
  
              'transformer' =&gt; function(AssetFileModel $asset) {
                  return [
                      'id' =&gt; $asset-&gt;title,
                      'src' =&gt; $asset-&gt;url,
                  ];
              },
         ],
      ]
  ];
  </code></pre>
  
  <hr>
  
  <p>The output you're seeing is defined by your <code>craft/config/elementapi.php</code> config file.</p>
  
  <p>You can read about that configuration file and all of the available settings in the Element API documentation at: <a href="https://github.com/craftcms/element-api/tree/v1#setup" rel="nofollow noreferrer">https://github.com/craftcms/element-api/tree/v1#setup</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T23:05:11.107Z
Answers.Text: Thanks. I'm pretty new to ElementAPI though, is there a way you could quickly help break it down for me? I'm picking up a little bit from this page, but not enough to make it work.
Answers.UserDisplayName: Jesse Winton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T23:13:14.310Z
Answers.Text: Can you edit the original question to include your `elementapi.php` file?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T23:14:58.387Z
Answers.Text: Yes, absolutely. Done.
Answers.UserDisplayName: Jesse Winton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-17T00:02:09.100Z
Answers.Text: Updated answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-17T21:30:55.887Z
Answers.Text: Can I have different 'resourceKey' values for a different endpoints?
Answers.UserDisplayName: Nikolay Bronskiy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-04T11:19:25.777Z
Answers.Text: Is it possible too remove the root 'data' completely?
Answers.UserDisplayName: nfq
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T22:33:54.500Z
Answers.LastActivityDate: 2017-05-17T19:44:08.203Z
Answers.LastEditDate: 2017-05-17T19:44:08.203Z
Answers.UserDisplayName: Brad Bell
Body: <p>Wondering if it's possible to change the output that I'm getting from ElementAPI. I'm using the API to preload assets, and this is the output I'm getting.</p>
  
  <pre><code>{
      "data": [
          {
              "title": "Hero",
              "url": "assets/hero.jpg"
          },
          {
              "title": "Profile",
              "url": "assets/profile.jpg"
          }
      ]
  }
  </code></pre>
  
  <p>This is great, and pretty much exactly what I need, but I'm wondering if there is a way to change the output so that, rather than using <code>"data":</code> I can use <code>"manifest":</code> which is what my preloader needs. Ideally, my code should look like this:</p>
  
  <pre><code>{
      manifest: [
          {
              "title": "Hero",
              "url": "assets/hero.jpg"
          },
          {
              "title": "Profile",
              "url": "assets/profile.jpg"
          }
      ]
  }
  </code></pre>
  
  <p>Here also is my <code>elementapi.php</code> file:</p>
  
  <pre><code>namespace Craft; 
  
  return [
      'endpoints' =&gt; [
          'assets/data/assets.json' =&gt; [
              'paginate' =&gt; false,
              'elementType' =&gt; ElementType::Asset,
              'criteria' =&gt; [
                  'limit' =&gt; null,
              ],
              'transformer' =&gt; function(AssetFileModel $asset) {
                  return [
                      'id' =&gt; $asset-&gt;title,
                      'url' =&gt; $asset-&gt;url,
                  ];
              },
         ],
      ]
  ];
  </code></pre>
  
  <p>If there isn't a way to do this in the plugin, is there a way to get the endpoint file and change it some other way?</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-16T23:39:24.730Z
Comments.Text: If I understand the question, that `data` key is provided by the plugin. You could modify the source to make all returned elements appear under a `manifest` key, but you will have to do some additional work to allow it to be configurable by each endpoint, individually. Check out Fractal's internals (https://github.com/craftcms/element-api/tree/v1/elementapi/vendor/league/fractal/src/Serializer) for how you might update those keys!
Comments.UserDisplayName: August Miller
Tags: <plugin-elementapi>
Title: Changing the output of ElementAPI
ThreadText: # Changing the output of ElementAPI
  
  (Asked by: username_0 on 2017-05-16)
  
  Wondering if it's possible to change the output that I'm getting from ElementAPI. I'm using the API to preload assets, and this is the output I'm getting.
  
  ```
  {
      "data": [
          {
              "title": "Hero",
              "url": "assets/hero.jpg"
          },
          {
              "title": "Profile",
              "url": "assets/profile.jpg"
          }
      ]
  }
  
  ```
  
  This is great, and pretty much exactly what I need, but I'm wondering if there is a way to change the output so that, rather than using `"data":` I can use `"manifest":` which is what my preloader needs. Ideally, my code should look like this:
  
  ```
  {
      manifest: [
          {
              "title": "Hero",
              "url": "assets/hero.jpg"
          },
          {
              "title": "Profile",
              "url": "assets/profile.jpg"
          }
      ]
  }
  
  ```
  
  Here also is my `elementapi.php` file:
  
  ```
  namespace Craft; 
  
  return [
      'endpoints' => [
          'assets/data/assets.json' => [
              'paginate' => false,
              'elementType' => ElementType::Asset,
              'criteria' => [
                  'limit' => null,
              ],
              'transformer' => function(AssetFileModel $asset) {
                  return [
                      'id' => $asset->title,
                      'url' => $asset->url,
                  ];
              },
         ],
      ]
  ];
  
  ```
  
  If there isn't a way to do this in the plugin, is there a way to get the endpoint file and change it some other way?
  
  Thanks!
  
  **Tags:** plugin-elementapi
  
  > **Comments:**
  > **username_1**: If I understand the question, that `data` key is provided by the plugin. You could modify the source to make all returned elements appear under a `manifest` key, but you will have to do some additional work to allow it to be configurable by each endpoint, individually. Check out Fractal's internals (https://github.com/craftcms/element-api/tree/v1/elementapi/vendor/league/fractal/src/Serializer) for how you might update those keys!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-05-16. Score: 2 | Accepted answer
  
  **Update:**
  
  Looks like changing the `'data'` key is a bit more difficult I suspected. We just released [Element API 1.3.0](https://github.com/craftcms/element-api/releases/tag/1.3.0) that exposes the internal `$resourceKey` necessary to change that value.
  
  In your `elementapi.php` config file, something like this should work:
  
  **UPDATE:** This is the final code that I used, and it works perfectly.
  
  ```
  return [
      'defaults' => [
          'resourceKey' => 'manifest'
      ],
  
      'endpoints' => [
          'assets/data/assets.json' => [
              'paginate' => false,
              'elementType' => ElementType::Asset,
  
              'transformer' => function(AssetFileModel $asset) {
                  return [
                      'id' => $asset->title,
                      'src' => $asset->url,
                  ];
              },
         ],
      ]
  ];
  
  ```
  
  ---
  
  The output you're seeing is defined by your `craft/config/elementapi.php` config file.
  
  You can read about that configuration file and all of the available settings in the Element API documentation at: <https://github.com/craftcms/element-api/tree/v1#setup>
  
  > **Comments:**
  > **username_0**: Thanks. I'm pretty new to ElementAPI though, is there a way you could quickly help break it down for me? I'm picking up a little bit from this page, but not enough to make it work.  
  > **username_2**: Can you edit the original question to include your `elementapi.php` file?  
  > **username_0**: Yes, absolutely. Done.  
  > **username_2**: Updated answer.  
  > **username_3**: Can I have different 'resourceKey' values for a different endpoints?  
  > **username_4**: Is it possible too remove the root 'data' completely?  
  
  ---
  
  