# Can't retrieve user metadata in Swift

**URL:** <https://community.auth0.com/t/cant-retrieve-user-metadata-in-swift/9794>\
**Category:** Get Help\
**Tags:** auth0swift, swift, management-api, auth0, user-metadata\
**Created:** [March 6, 2018, 1:22pm UTC](https://community.auth0.com/t/cant-retrieve-user-metadata-in-swift/9794 "2018-03-06T13:22:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eros](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Eros](https://community.auth0.com/u/Eros)\
**Post date:** [March 6, 2018, 1:22pm UTC](https://community.auth0.com/t/cant-retrieve-user-metadata-in-swift/9794/1 "2018-03-06T13:22:47Z")

</div>

Hi!  
I’m trying to retrieve the user\_metadata with the Auth0.swift toolkit but i have a problem.  
I’m using the following example that appear in the documentation:

> Blockquote  
> Auth0  
> .users(token: idToken)  
> .get(“user identifier”, fields: [“user\_metadata”], include: true)  
> .start { result in  
> switch result {  
> case .success(let userInfo):  
> print(“user: (userInfo)”)  
> case .failure(let error):  
> print(error)  
> }  
> }  
> Blockquote

But throws me this:

“Failed with unknown error [“attributes”: {  
error = “Invalid token”;  
}, “message”: Invalid token, “statusCode”: 401, “error”: Unauthorized]”

The token i’m using is the one thats is in the credentials returned from login.  
Any suggestions? Thanks!

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [March 14, 2018, 4:02pm UTC](https://community.auth0.com/t/cant-retrieve-user-metadata-in-swift/9794/2 "2018-03-14T16:02:50Z")

</div>

👋 @Eros

Would it be possible for you to share the snippet of code where you are making the authentication? It’ll help in solving your issue.

If you are trying to get metadata on the client side you’ll need to add it to your idToken by adding it in a rule [https://auth0.com/docs/scopes/current#example-add-custom-claims](https://auth0.com/docs/scopes/current#example-add-custom-claims)

In addition, have you specified the `user identifier` with id of the user and set the token to have the [scope](https://auth0.com/docs/scopes/current) `read:users` scope?

---

<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:** [July 25, 2019, 11:06am UTC](https://community.auth0.com/t/cant-retrieve-user-metadata-in-swift/9794/3 "2019-07-25T11:06:35Z")

</div>


