# Embed Discourse using external\_id

**URL:** https://meta.discourse.org/t/embed-discourse-using-external-id/266171
**Category:** Development
**Tags:** embedding
**Created:** [May 25, 2023, 9:23am UTC](https://meta.discourse.org/t/embed-discourse-using-external-id/266171 "2023-05-25T09:23:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![peterd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/peterd/32/281613_2.png) [@peterd](https://meta.discourse.org/u/peterd)
#### Post date: [May 25, 2023, 9:23am UTC](https://meta.discourse.org/t/embed-discourse-using-external-id/266171/1 "2023-05-25T09:23:12Z")

</div>

Hi all,

I’m migrating my community to Discourse. I have a lot of existing content in my current community. It seems that the Javascript embed option is a viable way to show topics and comments in my site’s pages.

To make it possible to link the community content after it is migrated to Discourse to the correct page, I’m considering to use the **external\_id** property.

I can set the property\_id for each topic programmatically via the API, but I don’t know how to make use of it in the embedded code.

I have tried this:

```plaintext
<script type="text/javascript">
  DiscourseEmbed = {
    discourseUrl: 'https://discourse.mydomain.com/',
    external_id: "296645"
  };

  (function() {
    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
  })();
</script>

```

but it doesn’t work.

Is there something else I can try?

---

<div class="post-metadata">

### Author: ![Aaron\_B](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aaron_b/32/327391_2.png) [@Aaron\_B](https://meta.discourse.org/u/Aaron_B)
#### Post date: [October 3, 2023, 5:14am UTC](https://meta.discourse.org/t/embed-discourse-using-external-id/266171/2 "2023-10-03T05:14:46Z")

</div>

Did you get this figured out? I’m needing to accomplish the same thing with the external\_id but I don’t think we have the variable name right.

To embed a specific topic, the variable is 'topicId". I’ve tried ‘externalId’ but haven’t found what works.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 3, 2023, 6:04am UTC](https://meta.discourse.org/t/embed-discourse-using-external-id/266171/3 "2023-10-03T06:04:09Z")

</div>

I think that what you are trying to do is outlined here [https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963#alternate-configuration-linking-to-existing-topics-6](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963#alternate-configuration-linking-to-existing-topics-6)

That would be useful for the case where you want to link existing posts from an external site with existing Discourse topics. That code would need to be added to each of the external posts that you wanted to link to Discourse. For each post, you would need to set the `topicId` parameter to the ID of the Discourse topic you wanted to link to.

If this doesn’t solve the problem for you, can you explain what you are trying to do in more details?

---

<div class="post-metadata">

### Author: ![Aaron\_B](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aaron_b/32/327391_2.png) [@Aaron\_B](https://meta.discourse.org/u/Aaron_B)
#### Post date: [October 3, 2023, 6:21am UTC](https://meta.discourse.org/t/embed-discourse-using-external-id/266171/4 "2023-10-03T06:21:18Z")

</div>

I split it out to it’s own thread which hopefully makes more sense:

> [@Expose external\_id in embed.js](https://meta.discourse.org/t/expose-external-id-in-embed-js/280834):
>
> I am needing to load posts on an external site where I don’t know the post\_id but I DO know the external\_id that I configured when I created the topic. Can someone please expose the external\_id variable in the embed.js logic or teach me what I’m missing? Example support needed: window.DiscourseEmbed = { discourseUrl: ‘[https://forums.blah.org/](https://forums.blah.org/)’, external\_id: ‘2023-4’ };
