# Accessing API resources by user id

**URL:** <https://community.auth0.com/t/accessing-api-resources-by-user-id/86994>\
**Category:** Get Help\
**Tags:** api, auth0\
**Created:** [July 14, 2022, 7:52pm UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994 "2022-07-14T19:52:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![konstantinov.v.konst](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konstantinov.v.konst/32/34570_2.png) [@konstantinov.v.konst](https://community.auth0.com/u/konstantinov.v.konst)\
**Post date:** [July 14, 2022, 7:52pm UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994/1 "2022-07-14T19:52:43Z")

</div>

I have a mobile app where the user logs in and an Tickets API from which the app retrieves the user’s tickets. The problem is that the GET tickets endpoint is such /tickets/{userid}. The userId is a GUID created inside my application, it is different from the auth0 user id. I have two questions about this:

1. When the user logs in the app how can the app retrieve the user’s application userId in order to be able to call the API.
2. Once the app has the userId, how can I secure the API in suck a way that this user can call the GET tickets endpoint only with this userId. For every other userId he should get a Forbidden response.

Thank you in advance and I will be glad to provide more details if needed. My API is written in C#.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 14, 2022, 11:21pm UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994/3 "2022-07-14T23:21:41Z")

</div>

Hello @konstantinov.v.konst welcome to the community!

> [@konstantinov.v.konst](#):
>
> When the user logs in the app how can the app retrieve the user’s application userId in order to be able to call the API.

When a user logs in via Auth0, depending on the implementation both the associated [ID token](https://auth0.com/docs/secure/tokens/id-tokens/id-token-structure#sample-id-token) and [Access token](https://auth0.com/docs/secure/tokens/access-tokens#sample-access-token) will have a `sub` claim which is the Auth0 user ID.

Alternatively, you could add an [Action](https://auth0.com/docs/customize/actions/actions-overview) that calls an API (that you would write) when a user is first created, grabs your external database userid. It would then add the userid to the user’s [app\_metadata](https://auth0.com/docs/manage-users/user-accounts/metadata) and eventually as a [custom claim to a token](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590).

> [@konstantinov.v.konst](#):
>
> Once the app has the userId, how can I secure the API in suck a way that this user can call the GET tickets endpoint only with this userId. For every other userId he should get a Forbidden response.

I recommend taking a look at our Architecture Scenarios documentation for an overview of what this may look like:

> **[Mobile Applications with API](https://auth0.com/docs/get-started/architecture-scenarios/mobile-api)**
>
> Explains the architecture scenario with a mobile application communicating with an API.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![konstantinov.v.konst](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konstantinov.v.konst/32/34570_2.png) [@konstantinov.v.konst](https://community.auth0.com/u/konstantinov.v.konst)\
**Post date:** [July 16, 2022, 6:45am UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994/4 "2022-07-16T06:45:40Z")

</div>

Thank you for your reply. I have a follow-up question.

> Alternatively, you could add an [Action](https://auth0.com/docs/customize/actions/actions-overview) that calls an API (that you would write) when a user is first created, grabs your external database userid.

How can I test Auth0 Actions locally. For instance, if I create an action that calls my local API, how can I redirect the call to my machine?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 27, 2022, 1:31am UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994/5 "2022-07-27T01:31:19Z")

</div>

Apologize for the delayed response on this one!

> [@konstantinov.v.konst](#):
>
> How can I test Auth0 Actions locally. For instance, if I create an action that calls my local API, how can I redirect the call to my machine?

Unfortunately because your local machine and the Auth0 authorization servers do not share the same instance you won’t be able to communicate with localhost 😕

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 11, 2022, 1:31am UTC](https://community.auth0.com/t/accessing-api-resources-by-user-id/86994/6 "2022-08-11T01:31:47Z")

</div>

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