Programmatically create a workspace before its creation

Currently, Twenty CRM does not provide a public API to programmatically create a workspace before its creation. Workspace creation is typically initiated through the user interface during the sign-up process. Did anyone here wrote a script / db queries to automate the sign-up process and the workspace creation without the user interface? THank you for your time! Ron
19 Replies
RonRonRon
RonRonRonOP2w ago
Maybe something like this?
const fetch = require('node-fetch');

const SERVER_IP = ...
const WORKSPACE_NAME = ...
const EMAIL = ...
const PASSWORD = ...
const FIRST_NAME = ...
const LAST_NAME = ...

// SignUp ...
// GetAuthTokensFromLoginToken ...
// UpdateOneWorkspaceMember
// etc.
const fetch = require('node-fetch');

const SERVER_IP = ...
const WORKSPACE_NAME = ...
const EMAIL = ...
const PASSWORD = ...
const FIRST_NAME = ...
const LAST_NAME = ...

// SignUp ...
// GetAuthTokensFromLoginToken ...
// UpdateOneWorkspaceMember
// etc.
Prastoin
Prastoin2w ago
Hello create a workspace before its création sorry unsure to understand this part Also unless I'm mistaken you can still create a workspace by hitting the signup with an already existing user that will result in creating a new workspace for this user ( this is handled in the endpoint directly)
RonRonRon
RonRonRonOP2w ago
Thank you @prastoin , maybe I should rephrase it to "Signup and create workspace programmatically for self-hosted env". The idea is that we want to automate the signup of a self-hosted setup and create the workspace programmatically once setup is done.
Prastoin
Prastoin2w ago
I think what you're looking for is the SignUpInNewWorkspace mutation
RonRonRon
RonRonRonOP2w ago
Great, so if I want to write a script automating this operation (without calling the graphql) I can directly call the signInUpService.signUpOnNewWorkspace command. Did someone here develop a script to do it from the command line? Do you think that it will be a good contribution to the community?
Prastoin
Prastoin2w ago
I'm not sure to understand when you would like to create a workspace exactly Why not hitting the api directly ? across your script rather than calling the service method ? The endpoint already exists so I don't think a command would be necessary If you don't want to hit the grapql API you can search for an existing endpoint on the REST one does not exist
RonRonRon
RonRonRonOP2w ago
Got it, that's why I thought a script for self-hosted use casewhere people want to configure the first workspace unattended. Not sure if someone else has this use case? maybe someone in the past and could share their script :20:
Prastoin
Prastoin2w ago
Twenty's images contains a default workspace
Prastoin
Prastoin2w ago
You can create a new workspace from the UI
No description
Prastoin
Prastoin2w ago
Hoping this anwers your question ! In case let me know !
RonRonRon
RonRonRonOP2w ago
Yep, the idea is not to use the UI, I am trying to automate it upon deployment - unattended, programmatically through a script that will take the workspace name, image, email, pass etc. and do the work without anyone clicking buttons 🐒
Prastoin
Prastoin2w ago
Each time you deploy you wanna create a new workspace ? Are you looking for tests seeders ?
RonRonRon
RonRonRonOP2w ago
Sorry I am not familiar with the term "tests seeder" but I am pretty sure I am not looking for it. I am looking to automate the creation of new crm env in my company with predefined goal / users / settings and this is an essential part of it
Prastoin
Prastoin2w ago
From my understanding each time you will deploy your application you expect your workspace to get reset completely by a new one ?
RonRonRon
RonRonRonOP2w ago
Yes, in my use case, after deploying the crm - my application will automatically create a new workspace without human intervention - unattended, with specific input that I give it - workspace name, users, etc
xBlaz3kx
xBlaz3kx2w ago
Also instead of test seeders, it would be nice if you could provide the emails and passwords to create in advance (per workspace)
Prastoin
Prastoin2w ago
Unless I'm mistaken official we planned Twenty SDK/ infra as code for around Q4 From now on I would recommended creating a script hitting your twenty api directly Or you can build your own Twenty image and ship your custom commands with it
RonRonRon
RonRonRonOP2w ago
Just curious if someone has a list of the mutations that are called when user onboards the system: 1. signUp 2. activateWorkspace 3. updateOneWorkspaceMember
Prastoin
Prastoin2w ago
You can find all available mutation in the graphql docs here https://twenty.com/developers/graphql/core I think what you're looking for are mutations: - signUpInNewWorkspace - activateWorkspace - updateWorkspaceMember Let me know if I can help !

Did you find this page helpful?