Default admin user via environment variables?

Hi,

Is there a way to create a default admin user from the environment variables.
I use docker and I would like to run the container with a default user already setup.

Thanks

1 Like

Hi @Romain1
No, but you can use the API to complete the setup:
https://github.com/metabase/metabase/wiki/Using-the-REST-API
https://github.com/metabase/metabase/blob/master/docs/api-documentation.md
Have a search in the forum for examples

Top uses the API we need at least 1 user to get an API key right? So I believe there will be no way to create a default user from the api if we don’t have a user already.

@Romain1 No, almost everything you can do in the Metabase interface (including the setup), you can do with the API.
The best way to learn the API, is to just use Metabase while having your browser developer Network-tab open and looking at the request, and what data is being send/received.

Hi there!
How can I get the right session token needed in the setting admin user API request?
According to the documentation, you need the user and password first.

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "cam@metabase.com", "password": "myPassword"}' \
  http://localhost:3000/api/session 

# -> {"id":"38f4939c-ad7f-4cbe-ae54-30946daf8593"}

For an example setup JSON, I always send some just generated token.

{
  "token": 38f4939c-ad7f-4cbe-ae54-30946daf8593,
  "user": {
    "password_confirm": "pass12345",
    "password": "pass12345",
    "site_name": "a",
    "email": "a@b.com",
    "last_name": "b",
    "first_name": "a"
  },
  "database": {
    "is_on_demand": false,
    "is_full_sync": true,
    "is_sample": false,
    "cache_ttl": null,
    "refingerprint": false,
    "auto_run_queries": true,
    "schedules": {},
    "details": {
      "host": "postgres",
      "port": 5432,
      "dbname": "post_db",
      "user": "postgres",
      "password": "password123",
      "schema-filters-type": "all",
      "ssl": false,
      "tunnel-enabled": false,
      "advanced-options": false
    },
    "name": "Postgres",
    "engine": "postgres",
    "database": {
      "host": "postgres",
      "port": 5432,
      "dbname": "post_db",
      "user": "postgres",
      "password": "password123",
      "schema-filters-type": "all",
      "ssl": false,
      "tunnel-enabled": false,
      "advanced-options": false
    }
  },
  "prefs": {
    "site_name": "a",
    "site_locale": "en",
    "allow_tracking": "true"
  }
}

the session token goes as a cookie, not a value in the body. Check what your browser doees