Skip to content

Grant database privileges

POST /api/v2/shared-hosting/{accountId}/database-users/{username}/privileges

Set a MySQL user’s privileges on one database. This links the user to the database. The user and the database must already exist on the account. A database name that does not exist on the account answers 502 upstream_failed. ALL PRIVILEGES gives full rights on that one database. A list that holds ALL PRIVILEGES grants all of them. Names are case-insensitive and duplicates are dropped. Any other value answers 400 invalid_request. The account must be active and on cPanel. The response repeats the user, the database and the privileges in upper case.

Authentication: An API key with the scopes write:hosting and console:services. About keys and scopes

Request

Path parameters

accountIdstringrequired
The web hosting account ID (acct_…).
usernamestringrequired
The database user’s ID (dbu_…) from Create database user, or its MySQL user name. Letters, digits and underscores.

Body

databasestringrequired
The full database name from GET /api/v2/shared-hosting/{accountId}/databases databases[].name.
privilegesarray of stringrequired
The privileges to set. 1 to 50 entries.

Example

POST /api/v2/shared-hosting/{accountId}/database-users/{username}/privileges
curl -X POST "https://cloud.hostup.se/api/v2/shared-hosting/acct_01hxa3b4c5d6e7f8g9h0j1k2m3/database-users/abcde_wp_exampleuser/privileges" \
-H "Authorization: Bearer $HOSTUP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"database": "abcde_wp_example",
"privileges": [
"ALL PRIVILEGES"
]
}'

Responses

200 Privileges set.

Response 200
{
"username": "abcde_wp_exampleuser",
"database": "abcde_wp_example",
"privileges": [
"ALL PRIVILEGES"
]
}
Response fields
usernamestring
The MySQL user name.
databasestring
The database.
privilegesarray of string
The privileges now set, in upper case.

Errors

Errors are Problem Details with a stable code. Branch on the code, not on the text.

400invalid_request. errors[0].pointer says what is wrong: /path/username for a user name or ID that is malformed or unknown, /body for a missing or malformed database, /body/privileges for an empty list or a privilege not in the list.
401Unauthorized. Authentication is required.
403forbidden. With requiredScopes in the body, the key lacks a scope. The key needs all the scopes in that list, although detail asks for one of them. Without requiredScopes, the hosting account is not active. Check serviceStatus on GET /api/v2/shared-hosting/{accountId}.
404Not found. The resource does not exist or is not owned by the caller.
409account_not_eligible_cpanel: the account is on Hostup’s previous hosting platform. Support moves it to cPanel at no charge.
429Rate limited. Retry after the limit resets. 429 responses include Retry-After seconds plus X-RateLimit-* headers.
500Internal error. Retry later or contact support if the issue persists.
502upstream_failed: the control panel did not set the privileges. A user or a database that does not exist on the account is one cause. Sending the same request again fails the same way. Check both with GET /api/v2/shared-hosting/{accountId}/database-users and GET /api/v2/shared-hosting/{accountId}/databases first.