{"record":{"id":"e9435f9e3804df6c","repo":"appwrite/appwrite","slug":"failed-to-create-api-key","errorCode":null,"errorMessage":"Failed to create API key","messagePattern":"Failed to create API key","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Appwrite/Platform/Tasks/Screenshot.php","lineNumber":195,"sourceCode":"        }\n\n        Console::info(\"Site created\");\n\n        $siteId = $site['body']['$id'];\n\n        // Prepare API key, incase it's needed as variable\n        $response = $client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [\n            'content-type' => 'application/json',\n            'x-appwrite-project' => 'console',\n            'cookie' => $cookieConsole\n        ], [\n            'name' => 'Screenshot API key',\n            'scopes' => \\array_keys(Config::getParam('projectScopes', []))\n        ]);\n\n        if ($response['headers']['status-code'] !== 201) {\n            Console::error(\\json_encode($response));\n            throw new \\Exception(\"Failed to create API key\");\n        }\n\n        $apiKey = $response['body']['secret'];\n\n        Console::info(\"API key created\");\n\n        $variables['APPWRITE_API_KEY'] = $apiKey;\n\n        // Create variables\n        if (!empty($template['variables'] ?? [])) {\n            foreach ($template['variables'] as $variable) {\n                $name = $variable['name'];\n\n                $value = $variable['value'];\n                $value = \\str_replace('{projectName}', $projectName, $value);\n                $value = \\str_replace('{projectId}', $projectId, $value);\n                $value = \\str_replace('{apiEndpoint}', 'http://' . System::getEnv('_APP_DOMAIN', '') . '/v1', $value);\n","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/appwrite/appwrite/blob/a1d520eea492ebd1da1ef2dc8db5b2b34e277dce/src/Appwrite/Platform/Tasks/Screenshot.php#L177-L213","documentation":"Error \"Failed to create API key\" thrown in appwrite/appwrite.","triggerScenarios":"Thrown at src/Appwrite/Platform/Tasks/Screenshot.php:195 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the logged API response for the exact error (e.g., invalid scopes).","Verify the 'projectScopes' config contains valid scope names for this Appwrite version.","Confirm the project was created successfully and the console session cookie is still valid."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a1d520eea492ebd1da1ef2dc8db5b2b34e277dce","analyzedAt":"2026-08-18T21:34:56.994Z","contentChangedAt":"2026-08-18T21:34:56.994Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}