# Publisher API reference

Base URL: https://store.worldstreetgold.com/api/v1/publisher

**Authentication.** Send `Authorization: Bearer ws_…`. Create keys in the console under the app → CI keys. Each key belongs to one app and has one or more scopes:

| Scope | Allows |
|---|---|
| `upload` | Create releases, upload APKs, read release status and app info |
| `publish_beta` | Publish `beta` and `internal` releases (never `stable`) |
| `ota` | Publish and manage OTA updates |

Everything else needs a signed-in person in the console: publishing to stable, approving, changing rollout percentage or halting, withdrawing, editing the listing, and managing keys and members.

**Conventions.**
- Bodies are JSON unless stated otherwise.
- Send an `Idempotency-Key: <uuid>` header on POSTs.
- Errors look like `{"error":{"code":"…","message":"…"}}`.

## Apps

**`GET /apps/{appId}?scope=upload|publish_beta|ota`**

Returns `{ id, slug, packageName, name }`. Any key bound to the app can call it, as long as it has the scope you pass.

**`POST /apps/{appId}/icon`** (scope: `upload`)

Multipart form with one field, `file`: a square PNG, JPEG or WebP, at least 192×192 (stored as 512×512 WebP). Changes the app's store icon immediately; it isn't tied to any release. Returns `{ iconKey }`.

## Releases (APKs)

**`POST /apps/{appId}/releases`** (scope: `upload`)

Body: `{ track: "beta"|"internal"|"stable", notesMd?: string, fileName?: string }`

Returns (201): `{ releaseId, uploadUrl, statusUrl, maxBytes }`. Limited to 10 per app per hour.

**`PUT /releases/{releaseId}/file`** (scope: `upload`)

Body: the raw APK bytes, with `Content-Type: application/vnd.android.package-archive`. Returns (202): `{ releaseId, status: "verifying", bytes }`.

**`GET /releases/{releaseId}`** (scope: `upload`)

Returns `{ id, status, track, versionCode, versionName, failureReason, rollout, artifact: { sha256, sizeBytes, certSha256[], scan, permissions[] } }`.

**`GET /apps/{appId}/releases`** (scope: `upload`)

Returns `{ releases: [{ id, versionCode, versionName, track, status, rollout, failureReason, createdAt }] }`.

**`POST /releases/{releaseId}/publish`** (scope: `publish_beta`; beta and internal only)

Body: `{ rolloutPercentage?: 1–100 (default 100), minSupportedVersionCode?: number|null, notesMd?: string }`

Returns `{ release, approvalNeeded, why[] }`.

## OTA updates (Expo)

**`HEAD` and `PUT /apps/{appId}/ota/assets/{sha256-base64url}`** (scope: `ota`)

Checks whether an asset is already stored, or uploads it.

**`POST /apps/{appId}/ota/updates`** (scope: `ota`)

Publishes a manifest. Use the CLI rather than building this request by hand; see https://store.worldstreetgold.com/docs/ota-updates.md.

**`POST /ota/{updateId}/rollout|rollback|restore|promote`** (scope: `ota`)

See the OTA guide.

## Public endpoints (no key)

- `GET /api/v1/apps/{packageName}/latest`: the latest published release, used by the SDK.
- `GET /apps/{slug}/releases.json`: the signed history of every published APK for an app. The signature is in the `X-Worldstore-Signature` header, and the public key is at `/.well-known/worldstore-signing-key.pem`. See https://store.worldstreetgold.com/verify.

## Download the CLI

```bash
curl -fsSLO https://store.worldstreetgold.com/cli/worldstore.mjs
node worldstore.mjs   # prints usage
```
