<p>I'm assuming that "welcome" is also your page slug.</p>

<p>You could query the craft_elements_i18n table (pseudo code):</p>

<pre><code>$sql = "select id from craft_elements_i18n where slug = 'welcome' limit 1"
$result = get($sql);
$entry_id = $result['id'];
</code></pre>

<p>Then feed that into your function.
Replace 'welcome' with a read of the uri to make it dynamic.</p>

CC BY-SA 4.0
2019-03-15T15:31:25.437Z
2019-03-15T15:31:25.437Z
Jim Wyse
<p>I want to configure deeplinks for an app and want to set up 'universal links'. Right now I'll send an entry id to the element api to get the right content. But with universal links I didn't have a entry id, only a url. Based on the url I'll need to get the right entry instead of based on the entry id.</p>

<p>Down here is my current endpoint to get the right entry based on a id. But if I didn't have an id how can I get the entry id based on the url.</p>

<p>for example website.com/pages/welcom has entry id 123, in the app I can open it with sending 123 to the api endpoint. With universal links I open a link from my mail app for example then the app launches and I can send 'website.com/pages/welcom' to the api but how I'll get the right content from that page that has entry id 123.</p>

<pre><code>'api/pages/&lt;entryId:\d+&gt;' =&gt; function($entryId) {

        requireLogin();

        return array(
            'elementType' =&gt; 'Entry',
            'criteria' =&gt; ['section' =&gt; 'pages', 'id' =&gt; $entryId],
            'transformer' =&gt; function(EntryModel $entry) {



                $bodyBlocks = [];
                foreach ($entry-&gt;contentBlokken as $block) {
                    switch ($block-&gt;type-&gt;handle) {
                        case 'tekst':
                            $bodyBlocks[] = [
                                'text' =&gt; $block-&gt;description-&gt;getParsedContent(),
                            ];
                            break;
                    }
                }

                return array(
                    'id' =&gt; $entry-&gt;id,
                    'title' =&gt; $entry-&gt;title,
                    'description' =&gt; $bodyBlocks,
                );
            }
        );
    },
</code></pre>

CC BY-SA 4.0
2019-03-13T22:03:22.207Z
Sorry, but I don't think I'm following 100%. Can you expand the question and maybe add some example URLs and code to elaborate?
Brad Bell
CC BY-SA 4.0
2019-03-15T10:45:47.160Z
@BradBell I updated my question hope I'll make it more clear.
Maarten Heideman
<entries><url><plugin-elementapi>
How I’ll get an entryId based on a given URL?
# How I’ll get an entryId based on a given URL?

(Asked by: username_0 on 2019-03-12)

I want to configure deeplinks for an app and want to set up 'universal links'. Right now I'll send an entry id to the element api to get the right content. But with universal links I didn't have a entry id, only a url. Based on the url I'll need to get the right entry instead of based on the entry id.
Down here is my current endpoint to get the right entry based on a id. But if I didn't have an id how can I get the entry id based on the url.
for example website.com/pages/welcom has entry id 123, in the app I can open it with sending 123 to the api endpoint. With universal links I open a link from my mail app for example then the app launches and I can send 'website.com/pages/welcom' to the api but how I'll get the right content from that page that has entry id 123.
'api/pages/' => function($entryId) {

        requireLogin();

        return array(
            'elementType' => 'Entry',
            'criteria' => ['section' => 'pages', 'id' => $entryId],
            'transformer' => function(EntryModel $entry) {



                $bodyBlocks = [];
                foreach ($entry->contentBlokken as $block) {
                    switch ($block->type->handle) {
                        case 'tekst':
                            $bodyBlocks[] = [
                                'text' => $block->description->getParsedContent(),
                            ];
                            break;
                    }
                }

                return array(
                    'id' => $entry->id,
                    'title' => $entry->title,
                    'description' => $bodyBlocks,
                );
            }
        );
    },

**Tags:** entries, url, plugin-elementapi

> **Comments:**
> **username_1**: Sorry, but I don't think I'm following 100%. Can you expand the question and maybe add some example URLs and code to elaborate?  
> **username_0**: @BradBell I updated my question hope I'll make it more clear.  

---

## 1 answers

### Answer by username_2 on 2019-03-15. Score: 2 | Accepted answer

I'm assuming that "welcome" is also your page slug.
You could query the craft_elements_i18n table (pseudo code):
$sql = "select id from craft_elements_i18n where slug = 'welcome' limit 1"
$result = get($sql);
$entry_id = $result['id'];

Then feed that into your function.
Replace 'welcome' with a read of the uri to make it dynamic.


---

