Quickstart
This walks through the whole flow with curl. Replace the capitalized placeholders with your own values.
1. Register your app
- Sign in to Treechat and open
https://api.treechat.com/developers/apps. - Choose Register an app and fill in:
- App name: shown to people when they connect, and on every post as “via App name”.
- Homepage: your site.
- Redirect URIs: 1 to 5 exact URLs Treechat may send people back to. Use
https, orhttp://localhostwhile you build. - Permissions: only the ones you need:
treechat:write,uploads:write,treechat:read,account:read.
- Save. Treechat shows a client ID and a client secret. The secret is shown once; store it on your server only. You can rotate it later from the app page.
Your app works for anyone as soon as it’s registered. There is no review queue.
2. Send the member to Treechat
Create a PKCE verifier and challenge for each sign-in:
VERIFIER=$(openssl rand -base64 48 | tr -d '=+/\n' | cut -c1-64)CHALLENGE=$(printf '%s' "$VERIFIER" | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=\n')Redirect the browser to:
https://api.treechat.com/mcp/oauth/authorize ?response_type=code &client_id=YOUR_CLIENT_ID &redirect_uri=https://yourapp.com/auth/treechat/callback &scope=treechat:write%20uploads:write%20treechat:read%20account:read &state=RANDOM_STATE &code_challenge=CHALLENGE &code_challenge_method=S256 &resource=https://api.treechat.com/mcpThe member signs in, sees your app’s name, homepage and developer, and chooses Allow. Treechat redirects to your redirect_uri with ?code=...&state=.... Check that state matches what you sent.
3. Trade the code for tokens
curl -X POST https://api.treechat.com/mcp/oauth/token \ -u YOUR_CLIENT_ID:YOUR_CLIENT_SECRET \ -d grant_type=authorization_code \ -d code=CODE_FROM_REDIRECT \ -d redirect_uri=https://yourapp.com/auth/treechat/callback \ -d code_verifier="$VERIFIER" \ -d resource=https://api.treechat.com/mcp{ "access_token": "…", "token_type": "Bearer", "expires_in": 900, "refresh_token": "…", "scope": "treechat:write uploads:write treechat:read account:read"}4. Check who connected
curl https://api.treechat.com/api/apps/v1/me \ -H "Authorization: Bearer ACCESS_TOKEN"{ "id": "af899143-…", "username": "clip_fan", "space_id": "…" }5. Post
curl -X POST https://api.treechat.com/api/apps/v1/posts \ -H "Authorization: Bearer ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: episode-1" \ -d '{"content":"Episode 1 is live","public":true}'{ "operation_id": "…", "state": "completed", "thread_id": "72db5fc4-…", "post_id": "…" }New threads are private unless you send "public": true.
Reply in the thread:
curl -X POST https://api.treechat.com/api/apps/v1/posts \ -H "Authorization: Bearer ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: episode-1-notes" \ -d '{"content":"Shot on a phone in one afternoon.","thread_id":"THREAD_ID"}'6. Read the thread
curl https://api.treechat.com/api/apps/v1/threads/THREAD_ID \ -H "Authorization: Bearer ACCESS_TOKEN"Next
- Attach images or video: Uploads.
- Keep the connection alive: Refreshing tokens.
- Handle retries safely: Idempotency.