Answers.Body: <p>Try</p>
  
  <pre><code>return [
  'endpoints' =&gt; [
      'products.json' =&gt; [
          'elementType' =&gt; 'Commerce_Product',
          'criteria' =&gt; [
              // 'category' =&gt; 'products', // randomly trying stuff here!
              // 'section' =&gt; 'products',
              // 'type' =&gt; 'products',
          ],
          'transformer' =&gt; function(Commerce_ProductModel $product) {
              return [
                  'title' =&gt; $product-&gt;title,
                  'url' =&gt; $product-&gt;url,
              ];
          },
      ]
  ]]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-23T00:16:29.007Z
Answers.Text: Thanks, but that's giving me the classic: No element type exists by the type “Commerce_Products”.
Answers.UserDisplayName: Chilly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-23T00:17:41.980Z
Answers.Text: Ah! drop the 's' ! : Commerce_Product
  
  thank you!
Answers.UserDisplayName: Chilly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-02T09:33:54.130Z
Answers.Text: If you are using Commerce 2, the `Commerce_Product` should be `Product` and add a `use craft\commerce\elements\Product` at the top of your file.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-23T00:07:59.520Z
Answers.LastActivityDate: 2017-03-23T04:49:07.210Z
Answers.LastEditDate: 2017-03-23T04:49:07.210Z
Answers.UserDisplayName: Luke Holder
Answers.Body: <p>For Commerce 2</p>
  
  <pre><code>use craft\commerce\elements\Product;
  return [
      'endpoints' =&gt; [
      'products.json' =&gt; [
          'elementType' =&gt; Product::class,
          'transformer' =&gt; function(Product $product) {
              return [
                  'title' =&gt; $product-&gt;title,
                  'url' =&gt; $product-&gt;url,
              ];
          },
      ],
      ]
  ];
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-08T02:59:08.923Z
Answers.LastActivityDate: 2018-10-08T02:59:08.923Z
Answers.UserDisplayName: Jack V
Body: <p>The <a href="https://github.com/craftcms/element-api/tree/v1#elementtype-required" rel="nofollow noreferrer">elementApi</a> docs state you can use custom elementTypes via plugins.  I am using craft commerce which states it creates the custom elementType '<a href="https://craftcommerce.com/docs/purchasables" rel="nofollow noreferrer">purchasable</a>'</p>
  
  <p>I've tried:</p>
  
  <pre><code>return [
  'endpoints' =&gt; [
      'category.json' =&gt; [
          'elementType' =&gt; 'purchasable',
          'criteria' =&gt; [
              // 'category' =&gt; 'products', // randomly trying stuff here!
              // 'section' =&gt; 'products',
              // 'type' =&gt; 'products',
          ],
          'transformer' =&gt; function(EntryModel $entry) {
              return [
                  'title' =&gt; $entry-&gt;title,
                  'url' =&gt; $entry-&gt;url,
              ];
          },
      ]
  ]]
  </code></pre>
  
  <p>I've tried many variations on the word purchasable, as we as random guesses like 'product', 'item' etc etc</p>
  
  <p>I should mention I am able to JSON back with all categories, Entries etc etc</p>
  
  <p>I am sure this is possible, as craft, craftcommerce and elementApi are all made by the same guys!</p>
  
  <p>Any help would be amazing</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-23T00:04:53.253Z
Comments.Text: What's the class name of your purchasable?
Comments.UserDisplayName: Brad Bell
Tags: <plugin-craftcommerce><plugin-elementapi>
Title: Get 'purchasable' from ElementAPI
ThreadText: # Get 'purchasable' from ElementAPI
  
  (Asked by: username_0 on 2017-03-22)
  
  The [elementApi](https://github.com/craftcms/element-api/tree/v1#elementtype-required) docs state you can use custom elementTypes via plugins. I am using craft commerce which states it creates the custom elementType '[purchasable](https://craftcommerce.com/docs/purchasables)'
  
  I've tried:
  
  ```
  return [
  'endpoints' => [
      'category.json' => [
          'elementType' => 'purchasable',
          'criteria' => [
              // 'category' => 'products', // randomly trying stuff here!
              // 'section' => 'products',
              // 'type' => 'products',
          ],
          'transformer' => function(EntryModel $entry) {
              return [
                  'title' => $entry->title,
                  'url' => $entry->url,
              ];
          },
      ]
  ]]
  
  ```
  
  I've tried many variations on the word purchasable, as we as random guesses like 'product', 'item' etc etc
  
  I should mention I am able to JSON back with all categories, Entries etc etc
  
  I am sure this is possible, as craft, craftcommerce and elementApi are all made by the same guys!
  
  Any help would be amazing
  
  **Tags:** plugin-craftcommerce, plugin-elementapi
  
  > **Comments:**
  > **username_1**: What's the class name of your purchasable?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-03-23. Score: 3 | Accepted answer
  
  Try
  
  ```
  return [
  'endpoints' => [
      'products.json' => [
          'elementType' => 'Commerce_Product',
          'criteria' => [
              // 'category' => 'products', // randomly trying stuff here!
              // 'section' => 'products',
              // 'type' => 'products',
          ],
          'transformer' => function(Commerce_ProductModel $product) {
              return [
                  'title' => $product->title,
                  'url' => $product->url,
              ];
          },
      ]
  ]]
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, but that's giving me the classic: No element type exists by the type “Commerce_Products”.  
  > **username_0**: Ah! drop the 's' ! : Commerce_Product  thank you!  
  > **username_2**: If you are using Commerce 2, the `Commerce_Product` should be `Product` and add a `use craft\commerce\elements\Product` at the top of your file.  
  
  ---
  
  ### Answer by username_3 on 2018-10-08. Score: 1
  
  For Commerce 2
  
  ```
  use craft\commerce\elements\Product;
  return [
      'endpoints' => [
      'products.json' => [
          'elementType' => Product::class,
          'transformer' => function(Product $product) {
              return [
                  'title' => $product->title,
                  'url' => $product->url,
              ];
          },
      ],
      ]
  ];
  
  ```
  
  
  ---
  
  