How to Delete X Posts Before Deactivating Your Account with TwexAPI
TwexAPI can help you delete posts from an authorized X account. It does not delete the X account itself. Account deactivation and permanent account deletion must be completed through X's official settings.
X's help page explains the account flow clearly: deactivation starts a 30-day window, and the account is permanently deleted if you do not log back in during that period. Request your X data archive before deactivating if you need a copy of your posts, messages, or media.
What TwexAPI Can and Cannot Do
| Goal | Use TwexAPI? | How to handle it |
|---|---|---|
| Delete one specific post | Yes | Call POST /twitter/tweets/delete-batch with target_id. |
| Delete posts from your authorized account | Yes | Call POST /twitter/tweets/delete-batch without target_id only after you have backed up and confirmed the action. |
| Permanently delete the X account | No | Use X settings: Settings and privacy, Your account, Deactivate your account. |
| Remove search engine copies | No | Follow the search engine's removal process; X does not control external indexes. |
Only use this workflow for an account you own or are explicitly authorized to manage.
Prepare Before Deleting Posts
Do these checks before calling any deletion endpoint:
- Download your X data archive from X settings if you need a copy.
- Revoke or review third-party app access so another tool does not reactivate or change the account unexpectedly.
- Test with one post ID before running a wider cleanup.
- Keep the API token and X cookie out of source control.
- Save a local log of deleted post IDs for your own audit trail.
Delete One Post
POST /twitter/tweets/delete-batch requires cookie and username. Add target_id when you want to delete one specific post.
curl --request POST \
--url https://api.twexapi.io/twitter/tweets/delete-batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"cookie": "auth_token=...",
"username": "your_username",
"target_id": "1234567890123456789"
}'The response returns the deleted post IDs in data.
{
"code": 200,
"msg": "success",
"data": ["1234567890123456789"]
}Delete Account Posts After Confirmation
If you omit target_id, the endpoint is documented for deleting all posts for the authorized username. Treat that as irreversible. The script below requires a confirmation environment variable so it does not run by accident.
1const token = process.env.TWEXAPI_BEARER_TOKEN;
2const cookie = process.env.X_AUTH_COOKIE;
3const username = process.env.X_USERNAME;
4const confirmDelete = process.env.CONFIRM_DELETE === "I_UNDERSTAND";
5
6if (!token || !cookie || !username) {
7 throw new Error("Set TWEXAPI_BEARER_TOKEN, X_AUTH_COOKIE, and X_USERNAME.");
8}
9
10if (!confirmDelete) {
11 throw new Error('Set CONFIRM_DELETE="I_UNDERSTAND" before deleting account posts.');
12}
13
14async function deleteAccountPosts() {
15 const response = await fetch("https://api.twexapi.io/twitter/tweets/delete-batch", {
16 method: "POST",
17 headers: {
18 Authorization: `Bearer ${token}`,
19 "Content-Type": "application/json",
20 },
21 body: JSON.stringify({
22 cookie,
23 username,
24 }),
25 });
26
27 const result = await response.json();
28 if (!response.ok || result.code !== 200) {
29 throw new Error(result.msg || `Delete request failed with ${response.status}`);
30 }
31
32 console.log(JSON.stringify({ deleted_ids: result.data || [] }, null, 2));
33}
34
35deleteAccountPosts().catch((error) => {
36 console.error(error.message);
37 process.exit(1);
38});Run it only after you have tested a single post deletion:
CONFIRM_DELETE="I_UNDERSTAND" \
TWEXAPI_BEARER_TOKEN="<token>" \
X_AUTH_COOKIE="auth_token=..." \
X_USERNAME="your_username" \
node delete-account-posts.jsDeactivate the X Account
After post cleanup, account deletion still happens in X:
- Open X and go to Settings and privacy.
- Open Your account.
- Choose Deactivate your account.
- Read the deactivation information and confirm with your password.
- Do not log back in during the deactivation window if your goal is permanent deletion.
Because X owns the account lifecycle, treat the official X help page as the source of truth if labels or timing change.
Wrap-up
Use TwexAPI for the part it can actually perform: deleting posts from an authorized account. Use X settings for account deactivation and permanent deletion.
That boundary makes the workflow safer, clearer, and much less likely to mislead someone into thinking an API call can erase an entire X account.