# Is it possible to Query a Postgres instance from an Action?

**URL:** <https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200>\
**Category:** Get Help\
**Tags:** actions\
**Created:** [June 29, 2022, 9:21pm UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200 "2022-06-29T21:21:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [June 29, 2022, 9:21pm UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200/1 "2022-06-29T21:21:27Z")

</div>

I have an old DB that contains some email to role mappings. I would like to use an action to pull in those mappings and inject them into the JWT as custom claims. Is this possible/recommended? Is there documentation on how to do this?

Also if I do it is it considered an external DB and does that increase my subscription price.

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [June 29, 2022, 11:29pm UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200/2 "2022-06-29T23:29:53Z")

</div>

Hi @jgleason

Thanks for contacting us at Auth0 Community.

I would recommend interfacing your old DB with an API (that can only do specific things) instead of connecting to your old DB directly from an Action. You can then use a package like Axios to connect to the API and get the data you need such as role mappings for a particular email address which would map to the user being registered in Auth0. You’ll need to use a Pre Registration Action and add the roles to the user\_metadata [https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow#store-a-user-id-from-another-system-in-the-user-profile](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow#store-a-user-id-from-another-system-in-the-user-profile)

Once the roles are in user\_metadata, you might create a Post Login Action to add those roles from user\_metadata into a users ID Token as custom claims [https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions#convert-custom-claims-in-tokens](https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions#convert-custom-claims-in-tokens) (After section)

This should get you started but let us know if you have any specific questions on any of this.

Warm regards.

---

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [July 5, 2022, 4:10pm UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200/3 "2022-07-05T16:10:52Z")

</div>

Assuming I did it this way how would I get a client cred token to communicate with the API? Would I have to use axios to call `/token` or is there an easier way to handle this in an action?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 8, 2024, 12:10pm UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200/4 "2024-01-08T12:10:35Z")

</div>

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 3, 2024, 2:58am UTC](https://community.auth0.com/t/is-it-possible-to-query-a-postgres-instance-from-an-action/86200/5 "2024-12-03T02:58:16Z")

</div>

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