# How to get external ID

**URL:** https://meta.discourse.org/t/how-to-get-external-id/258777
**Category:** Support
**Created:** [March 20, 2023, 6:30pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777 "2023-03-20T18:30:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gormus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gormus/32/428592_2.png) [@gormus](https://meta.discourse.org/u/gormus)
#### Post date: [March 20, 2023, 6:30pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777/1 "2023-03-20T18:30:01Z")

</div>

When I consume [API](https://docs.discourse.org/#tag/Admin/operation/adminGetUser) directly, I can access user’s external authentication ID without any problem:

```http
GET /admin/users/{id}.json

```

However, when I try using the Javascript API, I cannot get the same data for _the current user_. In fact, the `currentUser` doesn’t return any data for external IDs:

```js
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("1.5.0", api => {
  const currentUser = api.getCurrentUser();
  if (currentUser) {
    const userOAuthID = currentUser?.external_ids?.oauth2_basic;
    console.log("userOAuthID:", userOAuthID); // null
  }
});

```

How could I access `currentUser`’s external ID via javascript?

#### The Context

I’m trying to push current user’s external ID to `window.dataLayer`.

---

<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: [March 20, 2023, 6:53pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777/2 "2023-03-20T18:53:09Z")

</div>

> [@gormus](#):
>
> How could I access `currentUser`’s external ID via javascript?

It looks like you are trying to get the user’s `user_associated_account.provider_uid`. From looking at the code, there is a hidden site setting that you need to enable to cause the `associated_account_ids` to be returned from the `CurrentUserSerializer`:

> <https://github.com/discourse/discourse/blob/main/app/serializers/current_user_serializer.rb#L242-L254>

The `include_associated_account_ids` setting is hidden: [discourse/config/site\_settings.yml at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/config/site_settings.yml#L2078). To enable it, enter your site’s Rails console and run:

`SiteSetting.include_associated_account_ids=true`

---

<div class="post-metadata">

### Author: ![gormus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gormus/32/428592_2.png) [@gormus](https://meta.discourse.org/u/gormus)
#### Post date: [March 20, 2023, 7:02pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777/3 "2023-03-20T19:02:07Z")

</div>

> [@simon](#):
>
> The `include_associated_account_ids` setting is hidden: [discourse/site\_settings.yml at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/config/site_settings.yml#L2078). To enable it, enter your site’s Rails console and run:
> 
> `SiteSetting.include_associated_account_ids=true`

Thanks @simon.  
Though, it seems like it cannot be enabled on a hosted instance by myself. I find no option at `/admin/site_settings`

Likely solved! : )

---

<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: [March 20, 2023, 7:04pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777/4 "2023-03-20T19:04:05Z")

</div>

> [@gormus](#):
>
> it seems like it cannot be enabled on a hosted instance by myself.

If your site is hosted by Discourse, contact their support team. They should be able to set it for you.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 19, 2023, 7:04pm UTC](https://meta.discourse.org/t/how-to-get-external-id/258777/5 "2023-04-19T19:04:16Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
