# Invitation email template

**URL:** <https://community.auth0.com/t/invitation-email-template/80370>\
**Category:** Get Help\
**Tags:** invitations, email-template\
**Created:** [March 22, 2022, 10:53pm UTC](https://community.auth0.com/t/invitation-email-template/80370 "2022-03-22T22:53:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas.majewski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucas.majewski/32/33884_2.png) [@lucas.majewski](https://community.auth0.com/u/lucas.majewski)\
**Post date:** [March 22, 2022, 10:53pm UTC](https://community.auth0.com/t/invitation-email-template/80370/1 "2022-03-22T22:53:58Z")

</div>

I am trying to use user.app\_metadata.someprop in User Invitation email template but none of user.app\_metadata fields are getting populated. Not even user.picture. Only user.email works so far. I was expecting to be able to use any common variables. [Customize Email Templates](https://auth0.com/docs/customize/email/email-templates#common-variables)

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [March 23, 2022, 11:44pm UTC](https://community.auth0.com/t/invitation-email-template/80370/4 "2022-03-23T23:44:20Z")

</div>

Hi @lucas.majewski ,

Welcome to the Auth0 Community!

We are looking into this topic and will provide updates to you soon.

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [March 24, 2022, 12:09am UTC](https://community.auth0.com/t/invitation-email-template/80370/5 "2022-03-24T00:09:19Z")

</div>

tested with the following scripts in the body of the email template (verify email using link), and it’s working fine.

```auto
<h1>please setup your password {{user.app_metadata.color}}</h1>
              <h1>country is {{ user.email }}, {{ user.user_metadata.country }} </h1>
              
              <img 
                   src= {{ user.picture}}
                   width ="50"
                   alt="your picture"
                   />

```

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [March 24, 2022, 12:52am UTC](https://community.auth0.com/t/invitation-email-template/80370/6 "2022-03-24T00:52:53Z")

</div>

Hi @lucas.majewski ,

I tested this issue with the “Verification email with link” template and it works fine for me.

Here are my scripts:

```auto
<h1> {{user.app_metadata.color}}</h1>
<h1>country is {{ user.user_metadata.country }} </h1>
<img 
                   src= {{ user.picture}}
                   width ="50"
                   alt="your picture"/>

```

I tried to trigger the “user invitation” template in Management API with below scripts, it says successful, but email is not received for some reason.  
{  
“connection\_id”:“xxx”,  
“client\_id”:“xxx”,  
“email”: “xxx”,  
“includeEmailInRedirect”: false  
}

Ideally, if the scripts works for the “Verification email with Link” template, it should work for the “User Invitation” template as well.

Could you share with us your scripts in the body of the email template?

---

<div class="post-metadata">

**Author:** ![lucas.majewski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lucas.majewski/32/33884_2.png) [@lucas.majewski](https://community.auth0.com/u/lucas.majewski)\
**Post date:** [March 26, 2022, 3:26am UTC](https://community.auth0.com/t/invitation-email-template/80370/7 "2022-03-26T03:26:42Z")

</div>

Ultimately this script took care of:

1. onExecutePostUserRegistration
2. Add user to an org
3. Generate password change ticket
4. Send org invite with the change password ticket link via {{user.app\_metadata.must\_reset\_password\_link}}

/\*\*

- Handler that will be called during the execution of a PostUserRegistration flow.
- 
- @param {Event} event - Details about the context and user that has registered.  
\*/  
var ManagementClient = require(‘auth0’).ManagementClient;

const logPrefix = "WelcomeAndChangePassword: ";

exports.onExecutePostUserRegistration = async (event) =\> {  
const userId = event.user.user\_id;  
console.log(logPrefix, userId, “starting”);

const originating\_organization\_id = event.user.app\_metadata.originating\_organization\_id;  
if (!originating\_organization\_id)  
throw new Error(‘Missing 'user.app\_metadata.originating\_organization\_id'’);

const originating\_client\_id = event.user.app\_metadata.originating\_client\_id;  
if (!originating\_client\_id)  
throw new Error(‘Missing 'user.app\_metadata.originating\_client\_id'’);

const auth0MgmtClient = new ManagementClient({  
domain: event.tenant.id + ‘.us.auth0.com’,  
clientId: event.secrets.auth0MgmtClientId,  
clientSecret: event.secrets.auth0MgmtClientSecret,  
scope: ‘create:organization\_members create:organization\_invitations create:user\_tickets’,  
});

console.log(logPrefix, userId, “adding user to organization”, originating\_organization\_id);

await auth0MgmtClient.organizations.addMembers({  
id: originating\_organization\_id  
}, {  
members: [userId]  
});

console.log(logPrefix, userId, “creating password change ticket”, originating\_organization\_id, originating\_client\_id);

const loginUrl = event.user.app\_metadata.login\_url;

console.log(logPrefix, userId, “login\_url from from user.app\_metadata (not used)”, loginUrl);

let passwordChangeTicketResult = await auth0MgmtClient.createPasswordChangeTicket({  
//result\_url: loginUrl,  
organization\_id: originating\_organization\_id,  
client\_id: originating\_client\_id,  
user\_id: userId,  
includeEmailInRedirect: true,  
mark\_email\_as\_verified: true  
});

console.log(logPrefix, userId, “creating organization invitation”, originating\_organization\_id, originating\_client\_id);

await auth0MgmtClient.organizations.createInvitation({  
id: originating\_organization\_id  
}, {  
send\_invitation\_email: true,  
client\_id: originating\_client\_id,  
invitee: {  
email: event.user.email  
},  
inviter: {  
name: “Inviter”  
},  
app\_metadata: {  
must\_reset\_password\_link: passwordChangeTicketResult.ticket  
}  
});

console.log(logPrefix, userId, “finished”);  
};

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [March 28, 2022, 3:39pm UTC](https://community.auth0.com/t/invitation-email-template/80370/8 "2022-03-28T15:39:55Z")

</div>

Glad to know that you have figured out the solution. Thank you for sharing your scripts with us! 👏

---

<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:** [December 22, 2022, 10:59am UTC](https://community.auth0.com/t/invitation-email-template/80370/9 "2022-12-22T10:59:04Z")

</div>


