<p>When using the <a href="https://github.com/craftcms/element-api" rel="nofollow noreferrer">Element API</a>, how do you go about using the <a href="https://github.com/benjamminf/craft-embedded-assets" rel="nofollow noreferrer">Embedded Assets plugin</a>?</p>

<p>With a regular asset, in the API transformer you can pull out assets and include them like this:</p>

<pre><code>'transformer' =&gt; function(craft\elements\Entry $entry) {
    // Create an array of all the photo URLs
    $photos = [];
    foreach ($entry-&gt;photos-&gt;all() as $photo) {
        $photos[] = $photo-&gt;url;
    }

    return [
        'title' =&gt; $entry-&gt;title,
        'url' =&gt; $entry-&gt;url,
        'description' =&gt; (string)$entry-&gt;description,
        'photos' =&gt; $photos
    ];
},
</code></pre>

<p>This approach however gives me the URL to the <strong>json file</strong> that Embedded Assets uses to store some information about the video.</p>

<p>Is there a better way than parsing that file as json in php and pulling the iframe from that? Is there some plugin code that can be used to handle this more elegantly?</p>

CC BY-SA 4.0
2018-11-08T20:32:39.223Z
Hi James, what are you trying to get out of the Embed Assets and return?
CraftQuest
CC BY-SA 4.0
2018-11-13T03:40:15.687Z
Hi Ryan. I'm hoping to pull out either the "code" attribute (the iframe). I know I could parse the json file and pull it out that way, but I imagine there's a "proper" way to do it using plugin code.
JamesNZ
<craft3><plugin-elementapi><plugin-embeddedassets>
Using Embedded Assets Plugin With Element API
# Using Embedded Assets Plugin With Element API

(Asked by: username_0 on 2018-11-08)

When using the Element API, how do you go about using the Embedded Assets plugin?
With a regular asset, in the API transformer you can pull out assets and include them like this:
'transformer' => function(craft\elements\Entry $entry) {
    // Create an array of all the photo URLs
    $photos = [];
    foreach ($entry->photos->all() as $photo) {
        $photos[] = $photo->url;
    }

    return [
        'title' => $entry->title,
        'url' => $entry->url,
        'description' => (string)$entry->description,
        'photos' => $photos
    ];
},

This approach however gives me the URL to the json file that Embedded Assets uses to store some information about the video.
Is there a better way than parsing that file as json in php and pulling the iframe from that? Is there some plugin code that can be used to handle this more elegantly?

**Tags:** craft3, plugin-elementapi, plugin-embeddedassets
> **Comments:**
> **username_1**: Hi James, what are you trying to get out of the Embed Assets and return?  
> **username_0**: Hi Ryan. I'm hoping to pull out either the "code" attribute (the iframe). I know I could parse the json file and pull it out that way, but I imagine there's a "proper" way to do it using plugin code.  

---

## 0 answers

