Search code examples
javaspringspring-bootfusionauth

Creating Tenant in FusionAuth with java


How to write code to create new Tenant with fusionAuthClient? So that I can create a new Tenant with an API call.

Tenant  createTenant = new Tenant()
TenantRequest request = new TenantRequest(tenant);
        ClientResponse<TenantResponse, Errors> response = fusionAuthClient.createTenant(null, request);

What should I write in Tenant(), I had .with() and tried to configure it, but it keeps throwing NullPointerException. The null pointer exception is on .with(tenant -> tenant.externalIdentifierConfiguration.changePasswordIdGenerator.type = SecureGeneratorType.randomBytes)

and there are 12 NullPointerException on the Required Parameters. I tried to copy the config parameters from other Tenant that i created in FusionAuth.


Solution

  • I always use the API docs in conjunction with the client libraries.

    https://fusionauth.io/docs/v1/tech/apis/tenants/#create-a-tenant

    indicates that a number of attributes are required.

    It might be easier for you to copy an existing tenant by retrieving a tenant, tweaking the values and creating a new one.