Setup website database
Changed onCreates a new MySQL database for the website and writes its connection details into the website's environment variables, then restarts the application. The platform generates the password (and the database name and user, unless supplied). The password is never returned; the application reads it from the environment.
Written variables: DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD and DATABASE_URL (mysql://user:password@host:port/name, user and password percent-encoded). Existing variables are kept. If the website already has any variable with one of these names the call fails with 422 and nothing is created; the Replace Node.js environment variables endpoint removes them.
After this call the variables are ordinary environment variables: the Replace Node.js environment variables endpoint changes or removes them like any other.
A restart is enough for apps that read environment variables at process start, such as Express or NestJS. Frameworks that bake variables into the build output (Next.js, NEXT_PUBLIC_*) see the new values only after a fresh build (Start Node.js build endpoint).
A password in the request is ignored; the platform always generates it. The optional name and user are identifiers, not secrets.
Request
- Base URL: https://developers.hostinger.com
- URL: https://developers.hostinger.com/api/hosting/v1/accounts/{username}/websites/{domain}/databases/setup
- Auth: HTTP bearer
Path parameters
Domain name
Request body
Example request
{
"name": "u123456789_blog",
"user": "u123456789_blog_admin"
}Response
Success response
Example response
{
"database": {
"name": "u123456789_aB3dE",
"user": "u123456789_xY9zW",
"host": "localhost",
"port": 3306
},
"env_var_keys": [
"DB_HOST",
"DB_PORT",
"DB_NAME",
"DB_USER",
"DB_PASSWORD",
"DATABASE_URL"
]
}Changes
- info
endpoint added
- info