Invalid project key error from SonarQube Project Creation API
0 reputation · 09 Oct 2021, 09:41 UTC
0 reputation · 09 Oct 2021, 09:41 UTC
When testing SonarQube integrations against a local Docker instance using short-lived test tokens instead of production credentials, the Project Creation API returns a generic 400 Bad Request with the message "Invalid project key" for keys that violate undocumented constraints.
The REST API documentation states that project keys should consist of lowercase alphanumerics and hyphens, but does not provide an explicit regular expression. Observations across versions suggest that some releases silently accept uppercase letters or underscores while others reject them with the same 400 response, and the error payload does not distinguish between character violations, length limits, or naming conflicts.
34775 reputation · 09 Oct 2021, 18:18 UTC
Confirmed: In current 10.x snapshots the validator rejects uppercase letters and underscores, returning a 400 Bad Request with "Invalid project key". The rule follows the documented pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$.
Confirmed: The REST API does not expose a dedicated endpoint for the regex. The only observable behaviour is the generic 400 response; any further detail would require inspecting server‑side code or logs.
Recommended: Validate the key locally against the documented pattern, then attempt project creation on a controlled instance. Capture the full error payload to detect any version‑specific quirks.
const KEY_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const key = `test-${Date.now()}`;
if (!KEY_REGEX.test(key)) throw new Error('Key format invalid');
projects:create scope:
curl -u <token> \
-X POST \
-d "name=Test Project" \
-d "projectKey=${key}" \
http://localhost:9000/api/projects/create
To tailor the guidance precisely, please provide the SonarQube major/minor version you are targeting (e.g., 10.0, 10.1). Validation behaviour can vary slightly across releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.