# Unable to create custom claim with special character in the claim name

**URL:** <https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670>\
**Category:** JWT.io\
**Tags:** custom-claims, client-credentials-g, scopes, access-token, m2m-tokens\
**Created:** [June 21, 2023, 11:30am UTC](https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670 "2023-06-21T11:30:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatasandeep.kolis](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@venkatasandeep.kolis](https://community.auth0.com/u/venkatasandeep.kolis)\
**Post date:** [June 21, 2023, 11:30am UTC](https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670/1 "2023-06-21T11:30:05Z")

</div>

I am trying to create an access token with a custom claim with a special character in the claim name(ex: user\_email) but I see the generated token is not taking up the claim.

but I was successful with a special character(-), is this the expected behavior? character \_(underscore) is not allowed?

action:

exports.onExecuteCredentialsExchange = async (event, api) =\> {  
api.accessToken.setCustomClaim(“user\_email”, (event.request.body.useremail || “”));

};

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 21, 2023, 6:19pm UTC](https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670/3 "2023-06-21T18:19:51Z")

</div>

Hi @venkatasandeep.kolis,

Welcome to the Auth0 Community!

Yes! Appending custom claims with special characters like an underscore should work fine.

I did notice in your Action script that you are not using a namespaced URI to append your custom claims. This could lead to a scenario as you observed, where this claim is reserved and colliding an the existing claim. This causes your custom claim not to be added to your tokens.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/b/8/b820ff63de06b3f0cb1e3c15be99f8cff0861173.png)

(Reference: [Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims))

With that in mind, I recommend appending your custom claims using a namespaced URI. For example:

```auto
exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("https://my-api.exampleco.com/user_email", (event.request.body.useremail || “”));
};

```

Please let me know how this goes for you.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![venkatasandeep.kolis](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@venkatasandeep.kolis](https://community.auth0.com/u/venkatasandeep.kolis)\
**Post date:** [June 21, 2023, 6:39pm UTC](https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670/4 "2023-06-21T18:39:16Z")

</div>

Thanks, Rueben for your response. But I even tried with ‘preferred\_username’ and which is actually in the non-restricted category.

---

<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:** [July 5, 2023, 6:39pm UTC](https://community.auth0.com/t/unable-to-create-custom-claim-with-special-character-in-the-claim-name/109670/5 "2023-07-05T18:39:16Z")

</div>

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