[GH-ISSUE #434] Bulk Delete Threads #56

Closed
opened 2026-03-03 16:36:17 +03:00 by kerem · 6 comments
Owner

Originally created by @ilovefreesw on GitHub (May 16, 2024).
Original GitHub issue: https://github.com/NdoleStudio/httpsms/issues/434

When incoming messages are turned on, then the web UI can be come cluttered. There should be an option to bulk delete threads without opening them one by one.

Originally created by @ilovefreesw on GitHub (May 16, 2024). Original GitHub issue: https://github.com/NdoleStudio/httpsms/issues/434 When incoming messages are turned on, then the web UI can be come cluttered. There should be an option to bulk delete threads without opening them one by one.
kerem closed this issue 2026-03-03 16:36:18 +03:00
Author
Owner

@AchoArnold commented on GitHub (May 16, 2024):

@ilovefreesw I'm curious, how many thread do you really have that requires bulk delete?
Also, this is the reason why I created the archive feature, You can archive phone numbers who spam you so that you won't see them under your list of threads.

<!-- gh-comment-id:2115616153 --> @AchoArnold commented on GitHub (May 16, 2024): @ilovefreesw I'm curious, how many thread do you really have that requires bulk delete? Also, this is the reason why I created the archive feature, You can archive phone numbers who spam you so that you won't see them under your list of threads.
Author
Owner

@ilovefreesw commented on GitHub (May 17, 2024):

Basically, I get SMS from bank, promotions, some personal sms from friends or acquaintances that I don't want to sync to httpsms, and more. Currently I have around 210 threads this month only.

<!-- gh-comment-id:2116651666 --> @ilovefreesw commented on GitHub (May 17, 2024): Basically, I get SMS from bank, promotions, some personal sms from friends or acquaintances that I don't want to sync to httpsms, and more. Currently I have around 210 threads this month only.
Author
Owner

@AchoArnold commented on GitHub (May 17, 2024):

I see I'll keep this open to be implemented sometime in the future. In the meantime you can use the API to delete all the threads in a loop thread delete API

<!-- gh-comment-id:2116681363 --> @AchoArnold commented on GitHub (May 17, 2024): I see I'll keep this open to be implemented sometime in the future. In the meantime you can use the API to delete all the threads in a loop [thread delete API](https://api.httpsms.com/index.html#/MessageThreads/delete_message_threads__messageThreadID_)
Author
Owner

@AchoArnold commented on GitHub (Jun 9, 2024):

image

<!-- gh-comment-id:2156751519 --> @AchoArnold commented on GitHub (Jun 9, 2024): ![image](https://github.com/NdoleStudio/httpsms/assets/4196457/b2ee3ed5-3ccd-42be-880f-13683e0a18c5)
Author
Owner

@ilovefreesw commented on GitHub (Oct 5, 2024):

I use this script... leaving it here .. might help someone else:

async function deleteThreadsFromAnchorLinks(selector, apiKey) {
  if (!selector || typeof selector !== 'string') {
    throw new Error('Invalid selector provided.');
  }

  if (!apiKey || typeof apiKey !== 'string') {
    throw new Error('Invalid or missing API key.');
  }

  const baseUrl = 'https://**YourAPIDomain**/v1/message-threads/';

  try {
    const elements = document.querySelectorAll(selector);
    const threadIds = [];

    for (const element of elements) {
      const url = element.href;
      if (typeof url !== 'string') {
        console.warn(`Skipping invalid URL: ${url}`);
        continue;
      }
      const urlParts = url.split('/');
      const lastPart = urlParts[urlParts.length - 1];

      // Extract thread ID using a regular expression (more reliable)
      const threadIdMatch = lastPart.match(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i);

      if (threadIdMatch) {
        threadIds.push(threadIdMatch[0]);
      } else {
        console.warn(`Unable to extract thread ID from URL: ${url}`);
      }
    }

    if (threadIds.length === 0) {
      throw new Error('No thread IDs found in the anchor links.');
    }

    const deletionPromises = threadIds.map(async (threadId) => {
      const url = `${baseUrl}${threadId}`;
      const options = {
        method: 'DELETE',
        headers: {
          'accept': 'application/json',
          'x-api-Key': apiKey,
        },
      };

      const response = await fetch(url, options);

      if (!response.ok) {
        console.error(`Error deleting thread ${threadId}: ${await response.text()}`);
      } else {
        console.log(`Thread ${threadId} deleted successfully.`);
      }
    });

    await Promise.all(deletionPromises); // Wait for all deletions to finish
  } catch (error) {
    console.error('Error deleting threads:', error);
  }
}

// Replace with your actual CSS selector and API key
const selector = "div.v-item-group a"; // Adjust this to match your HTML structure
const apiKey = '**YourAPIKey**'; // Replace with your actual API key

deleteThreadsFromAnchorLinks(selector, apiKey)
  .then(() => console.log('All threads deleted (if successful).'))
  .catch((error) => console.error('Error deleting threads:', error));

Just have to replace API Key and API Domain. Paste the script in console on the threads page and let it delete all of them.

<!-- gh-comment-id:2394977423 --> @ilovefreesw commented on GitHub (Oct 5, 2024): I use this script... leaving it here .. might help someone else: ``` async function deleteThreadsFromAnchorLinks(selector, apiKey) { if (!selector || typeof selector !== 'string') { throw new Error('Invalid selector provided.'); } if (!apiKey || typeof apiKey !== 'string') { throw new Error('Invalid or missing API key.'); } const baseUrl = 'https://**YourAPIDomain**/v1/message-threads/'; try { const elements = document.querySelectorAll(selector); const threadIds = []; for (const element of elements) { const url = element.href; if (typeof url !== 'string') { console.warn(`Skipping invalid URL: ${url}`); continue; } const urlParts = url.split('/'); const lastPart = urlParts[urlParts.length - 1]; // Extract thread ID using a regular expression (more reliable) const threadIdMatch = lastPart.match(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i); if (threadIdMatch) { threadIds.push(threadIdMatch[0]); } else { console.warn(`Unable to extract thread ID from URL: ${url}`); } } if (threadIds.length === 0) { throw new Error('No thread IDs found in the anchor links.'); } const deletionPromises = threadIds.map(async (threadId) => { const url = `${baseUrl}${threadId}`; const options = { method: 'DELETE', headers: { 'accept': 'application/json', 'x-api-Key': apiKey, }, }; const response = await fetch(url, options); if (!response.ok) { console.error(`Error deleting thread ${threadId}: ${await response.text()}`); } else { console.log(`Thread ${threadId} deleted successfully.`); } }); await Promise.all(deletionPromises); // Wait for all deletions to finish } catch (error) { console.error('Error deleting threads:', error); } } // Replace with your actual CSS selector and API key const selector = "div.v-item-group a"; // Adjust this to match your HTML structure const apiKey = '**YourAPIKey**'; // Replace with your actual API key deleteThreadsFromAnchorLinks(selector, apiKey) .then(() => console.log('All threads deleted (if successful).')) .catch((error) => console.error('Error deleting threads:', error)); ``` Just have to replace API Key and API Domain. Paste the script in console on the threads page and let it delete all of them.
Author
Owner

@AchoArnold commented on GitHub (Oct 7, 2024):

There is no need to make it complicated for yourself @ilovefreesw

Call this API to get the list of message threads: https://api.httpsms.com/index.html#/MessageThreads/get_message_threads
And then call this API to delete the threads: https://api.httpsms.com/index.html#/MessageThreads/delete_message_threads__messageThreadID_

<!-- gh-comment-id:2396356319 --> @AchoArnold commented on GitHub (Oct 7, 2024): There is no need to make it complicated for yourself @ilovefreesw Call this API to get the list of message threads: https://api.httpsms.com/index.html#/MessageThreads/get_message_threads And then call this API to delete the threads: https://api.httpsms.com/index.html#/MessageThreads/delete_message_threads__messageThreadID_
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/httpsms#56
No description provided.