Setting custom user id via script

My Setup:

  • SeaTable Dedicated

My Problem:

I want to create a user with data from a table. I use a user API token and can set email, name and password. But I did not found anything to set the field “ID” from the user record (custom id). I tried to reference it as id and user_id but both did not work.

Any ideas how I can set it?

Code snippet:

Here is a snippet from my script:

        # Die aktuell ausgewählte Zeile aus dem Kontext holen
        current_row = getattr(context, "current_row", None)
        
        if current_row:
            # Daten für den neuen Benutzer vorbereiten
            # Passe die Feldnamen ("Email", "Name", "Initial PW") ggf. an deine Tabelle an
            email = current_row.get("Email")
            name = current_row.get("Name")
            custom_id = current_row.get("User ID")
            password = current_row.get("Initial PW")
            
            if not email:
                print("Fehler: Keine E-Mail-Adresse in der Zeile gefunden.")
                return

            # API-Endpunkt für die Erstellung von Benutzern in SeaTable Admin
            url = f"{SERVER_URL}/api/v2.1/admin/users/"
            
            headers = {
                "Authorization": f"Token {ADMIN_API_TOKEN}",
                "Content-Type": "application/json"
            }
            
            # Nutzlast (Payload) für den neuen Benutzer
            payload = {
                "email": email,
                "name": name,
                "custom_id": custom_id, # only 'id' does not work
                "password": password
            }
            
            # Anfrage an SeaTable senden
            response = requests.post(url, json=payload, headers=headers)

[...]

What you are looking for is the id_in_org.

I was close to this help page. :grin:

I just tried id_in_org instead of custom_id but no success. So I tried the Get User method (as described in Get User) and could see id_in_org in the response (from the current logged-in user).

I do not understand why I can use it (see it) when I read the record but cannot use it to set it.

BTW: I cannot set a phone number via script or the browser as well. All types of phone numbers are flagged as “phone invalid”. I tried multiple formats.

That’d be way too easy :wink:

Ok, now seriously, I have created an internal ticket. We’ll improve the addnewuser endpoint.

This is my actual script (snippet):

[...]

if current_row:
# Daten für den neuen Benutzer vorbereiten
# Passe die Feldnamen ("Email", "Name", "Initial PW") ggf. an deine Tabelle an
email = current_row.get("Email")
name = current_row.get("Name")
id_in_org = current_row.get("User ID")
phone = "+4912345678"
password = current_row.get("Initial PW")


# API-Endpunkt für die Erstellung von Benutzern in SeaTable Admin
url = f"{SERVER_URL}/api/v2.1/admin/users/"

headers = {
	"Authorization": f"Token {ADMIN_API_TOKEN}",
	"Content-Type": "application/json"
}

# Nutzlast (Payload) für den neuen Benutzer
payload = {
	"email": email,
	"name": name,
	"id_in_org": id_in_org,
	"phone": phone,
	"password": password
}

# Anfrage an SeaTable senden
response = requests.post(url, json=payload, headers=headers)

[...]

And this is what I get when I query the user above:

Both, id_in_org and phone are empty. And when I check the Scriptlog (I added the variables to the log) I can see that the variables are set: