appwrite / appwrite/sdk-for-cli

bug: `projects create-platform` fails with "Access to this API is forbidden" in CLI v16

Open
#282 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
100
Forks
45
Avg merge
1d 1h
Merged PRs (30d)
5

Description

# Bug Description

Running `appwrite projects create-platform` fails with:

```
Error: Access to this API is forbidden.
```

And if no `appwrite.config.json` exists in the current directory, it fails earlier with:

```
Error: Project is not set. Please run appwrite init project to initialize...
```

## Steps to Reproduce

1. Install `appwrite-cli@16.0.0`
2. Run `appwrite login`
3. Run:
```bash
appwrite projects create-platform \
--project-id \
--type web \
--name "My App" \
--hostname localhost
```
4. Observe: `Error: Access to this API is forbidden.`

## Root Cause

In `dist/cli.cjs`, `getProjectsClient` uses `sdkForProject()` instead of `sdkForConsole()`:

```ts
// ❌ Current (broken) — sets x-appwrite-project to local project ID
const getProjectsClient = async () => {
const sdkClient = await sdkForProject();
...
};
```

The server-side `projects.php` enforces that `x-appwrite-project` must be `console`:

```php
if ($project->getId() !== 'console') {
throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN);
}
```

The fix is to use `sdkForConsole()`, which correctly sets `x-appwrite-project: console`. This matches the behavior of the old `lib/commands/projects.js` before the TypeScript migration.

```ts
// ✅ Fix
const getProjectsClient = async () => {
const sdkClient = await sdkForConsole();
...
};
```

This affects **all** `appwrite projects` subcommands (`create-platform`, `list-platforms`, `create-key`, `list-keys`, etc.).

## Environment

- **CLI version:** 16.0.0
- **Appwrite server:** 1.8.1 (self-hosted)
- **Node:** v22.x

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.