TwitterAPIs Docs
API ReferenceWrite Actions

Leave an X Community API | Twitter Community Leave

Remove your X account from a community it belongs to, by the community's numeric id. The call runs as your registered X session, sends one leave request and reports what X answered, without reading the community first. Billed at $0.0008 per applied write; a leave that does not apply is free. Cost: $0.0008 per call.

Leave Community removes your own X account from an X Community it belongs to. Pass the numeric community_id; the call runs as your registered X session (or auth_token and ct0 sent with the call) and answers status left on success. Leaving a community the account is not in answers 409 not_member. One $0.0008 write, billed only when the leave applies.

POST
/community/leave

Authorization

bearerAuth
AuthorizationBearer <token>

Pass your API key as a bearer token on every request: Authorization: Bearer <API_KEY>.

In: header

Query Parameters

community_id?string

The same community id sent in the query string instead of the JSON body. Use one or the other; the body field is not required when this is present.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/community/leave?community_id=1493446837214187523" \  -H "Content-Type: application/json" \  -d '{    "community_id": "1493446837214187523"  }'
{  "ok": true,  "action": "community_leave",  "community_id": "1493446837214187523",  "status": "left",  "community": null}
{  "error": "bad_request",  "message": "`community_id` must be a numeric X community id, e.g. 1493446837214187523 (the digits in x.com/i/communities/<id>)."}
{  "error": "session_dead",  "message": "Your registered Twitter session is no longer valid. Re-register via POST /twitter/customer/session."}
{  "error": "insufficient_credits",  "message": "Your balance is exhausted. Top up your credits to continue."}
{  "ok": false,  "action": "community_leave",  "community_id": "1493446837214187523",  "status": null,  "error": "account_locked",  "message": "X reports the linked account is locked (X code 326). Unlock it in the X app first. A registered session has been marked dead and must be re-registered.",  "community": null}
{  "ok": false,  "action": "community_leave",  "community_id": "1493446837214187523",  "status": null,  "error": "community_not_found",  "message": "No community exists with this id, or it is not available to the linked account.",  "community": null}
{  "ok": false,  "action": "community_leave",  "community_id": "1493446837214187523",  "status": null,  "error": "not_member",  "message": "The linked account is not a member of this community, so there is nothing to leave.",  "community": null}
{  "ok": false,  "action": "community_leave",  "community_id": "1493446837214187523",  "status": null,  "error": "write_not_applied",  "message": "X did not apply this change. See `reason` for X's own classification.",  "community": null,  "reason": "upstream_error"}
{  "error": "rate_limited",  "message": "Upstream throttled or blocked this request. Retry shortly.",  "reason": "rate_limited"}
{  "error": "error",  "message": "Upstream request failed.",  "reason": "upstream_error"}

Pricing

UnitPrice
Per call$0.0008
Per 1,000 calls$0.80

One $0.0008 write, and you are not charged when the leave does not apply. Every non-200 answer is free.

When to use

Use it to drop your account out of communities programmatically, for example leaving the ones Community Memberships shows you no longer post in.

Notes

  • Other 409 answer: session_required when the key has no registered session and none was sent with the call. Other 403 answers: account_suspended (X code 64), and forbidden when X refuses the action for the account.
  • Every non-200 answer is free. A 200 whose upstream answer carried an error is never reported as a success.
  • The error bodies for not_member, community_not_found and account_suspended or account_locked carry the same layout as the 200 (ok, action, community_id, status, community) plus error and message, and may also carry a machine-readable reason.

FAQ

Does this need my own X session?

Yes. Leaving changes which account is a member, so it runs as the account you registered with POST /customer/session, or as the auth_token and ct0 you send with the call.

What if the account is not a member?

You get a 409 not_member, nothing changes, and you are not billed.

How do I list the communities my account is in?

Call Community Memberships with your account's numeric user_id. Each community it returns has an id you can pass here.

Was this page helpful?