# Create Organization in rules

**URL:** <https://community.auth0.com/t/create-organization-in-rules/62057>\
**Category:** Get Help\
**Tags:** organizations, rule, hooks\
**Created:** [May 1, 2021, 7:11pm UTC](https://community.auth0.com/t/create-organization-in-rules/62057 "2021-05-01T19:11:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali.sabryali7](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ali.sabryali7/32/27094_2.png) [@ali.sabryali7](https://community.auth0.com/u/ali.sabryali7)\
**Post date:** [May 1, 2021, 7:11pm UTC](https://community.auth0.com/t/create-organization-in-rules/62057/1 "2021-05-01T19:11:55Z")

</div>

Hi,

I am trying to create an organization in a rule. i am following these instructions [Get Management API Access Tokens for Production](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) to create an accessToken that is able to call management apis. when logging the response i am always getting “{ error: ‘access\_denied’, error\_description: ‘Unauthorized’ }” however when i run the same request on postman it returns an accessToken.

1. Is it possible to create a management api access Token to call management api from the rules usign M2M application credentials?
2. Is it possible to create a management api access Token to call management api from the hooks (pre-register) usign M2M application credentials?
3. I need every user that sign up to create a new organization and to be assigned to that organization. how can I achieve this behavior? (Multi Tenancy) just like auth0 multi tenancy flow. on first signup a default tenant is created and we are able to create a new tenant and switch between. Can this flow be implemented using the NEW organization auth0 feature ?

Thank you

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 4, 2021, 12:22pm UTC](https://community.auth0.com/t/create-organization-in-rules/62057/3 "2021-05-04T12:22:30Z")

</div>

Hi @ali.sabryali7,

Welcome to the Community!

> [@ali.sabryali7](#):
>
> Is it possible to create a management api access Token to call management api from the rules usign M2M application credentials?

Yes, in fact, there is a cached Access Token rules can access which you can read about in the [docs](https://auth0.com/docs/rules/use-management-api). However, the scope is limited to `read:users` and `update:users`:

> The Access Token for the Management API, which is available through `auth0.accessToken` , is limited to the `read:users` and `update:users` scopes

Since you need the scope `create:organizations`, you would need to create a new machine-to-machine (M2M) application and authorize it to use the Management API with the `create:organizations`.  
This answer outlines the steps for creating the M2M and writing the rule: [Prevent user creation (with hook?) if user is not whitelisted with rule - #5 by stephanie.chamblee](https://community.auth0.com/t/prevent-user-creation-with-hook-if-user-is-not-whitelisted-with-rule/62000/5)

> [@ali.sabryali7](#):
>
> Is it possible to create a management api access Token to call management api from the hooks (pre-register) usign M2M application credentials?

Yes, you would also create a M2M application just like you would for a rule described above.

> [@ali.sabryali7](#):
>
> Can this flow be implemented using the NEW organization auth0 feature ?

It sounds like it might be possible, but I will have to do some research to know for sure. I see that you have a ticket for this as well, so I will update here when resolved.

---

<div class="post-metadata">

**Author:** ![ali.sabryali7](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ali.sabryali7/32/27094_2.png) [@ali.sabryali7](https://community.auth0.com/u/ali.sabryali7)\
**Post date:** [May 6, 2021, 3:27pm UTC](https://community.auth0.com/t/create-organization-in-rules/62057/5 "2021-05-06T15:27:44Z")

</div>

My management api access token issue has been resolved 🙂 thank you.  
I have implemented the logic for creating organization, assigning user to be a member in the organization. enabling organization connections. in a rule that only runs if a user is not assigned to any member. Please update us with your research results

Thank you

---

<div class="post-metadata">

**Author:** ![Marcos\_Castany](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcos_castany/32/5991_2.png) [@Marcos\_Castany](https://community.auth0.com/u/Marcos_Castany)\
**Post date:** [May 17, 2021, 11:00am UTC](https://community.auth0.com/t/create-organization-in-rules/62057/6 "2021-05-17T11:00:17Z")

</div>

> [@ali.sabryali7](#):
>
> I need every user that sign up to create a new organization and to be assigned to that organization. how can I achieve this behavior? (Multi Tenancy) just like auth0 multi tenancy flow. on first signup a default tenant is created and we are able to create a new tenant and switch between. Can this flow be implemented using the NEW organization auth0 feature ?

Hi Ali

What you could do is the following:

On your site, have a registration form that would ask the end user for the organization details they want to register and the user’s email address. When the user submits that form, on the backend you create an organization with the proper connection and then send an invite to that email. With the invite, the user will be added to that organization after signup. You could also include roles in that invite flow. Would that work ?

---

<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:** [June 1, 2021, 11:00am UTC](https://community.auth0.com/t/create-organization-in-rules/62057/7 "2021-06-01T11:00:26Z")

</div>

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