r/GoogleAppsScript • • 7h ago

Question Errors from long standing and working script(s)...

So I've got a function, long standing which works|worked fine until lately and I am getting this:

GoogleJsonResponseException: API call to gmail.users.messages.delete failed with error: Requested entity was not found.

Code:

function deleteForever(userId, labelName) {

var threads = GmailApp.search("in:trash");

for (var i = 0; i < threads.length; i++) {

Gmail.Users.Messages.delete('[me]', threads[i].getId());

}

}

[me] is clearly a placeholder for the gmail address..

I've also tried it with .remove too... Same error.

I've tried using delete v. remove, and even this:

function DeleteMail() {
  var threads = GmailApp.search('in:trash');
  for (var i = 0; i < threads.length; i++) {
    var thisId = threads[i].getId();
    Gmail.Users.Messages.remove('[me]', thisId);
  }
}

Gets:

GoogleJsonResponseException: API call to gmail.users.messages.delete failed with error: Requested entity was not found.

DeleteMail

@

YES there is message in the trash.. lots of them actually... so??? shrug...

I ain't no ECMAScript guy, nor the variant(s) of it that google etc. adulterate ...

The only thing I can think is there is TOO MUCH TRASH? Variable overflow? Well then say that! Urrghhh..

So...?? Ideas??? Thanks!

1 Upvotes

4 comments sorted by

1

u/llzellner 5h ago

u/No-Sheepherder7116
The 404 is a thread ID vs. message ID mix-up — that's why it fails even though Trash is full.

Hmmm.. seems odd, as it has WORKED for YEARS this way.. then all of a sudden I get failures... hmmmmm..

I think you are on to something with a possible change in things.. since I don't use this for much, and its been setup and forget it till now...

Thanks for info...

1

u/roy1979 6h ago

Try this:
function deleteForever() {

var threads = GmailApp.search('in:trash');

for (var i = 0; i < threads.length; i++) {

Gmail.Users.Threads.remove('me', threads[i].getId());

}

}

1

u/llzellner 5h ago

This! THIS ! Seems to be working I think something changed like the other message mentioned (I have no clue where it went.. shrug...)

" won't help either — there is no `remove` method on Threads in the Advanced Gmail service, so that call fails too. You have two correct options: **1. Delete at thread level (the simplest way to empty Trash):** ```

I think there was some ABI something change that maybe would be noticed if you used this stuff day to day, but I don't.. this stuff was setup years ago to automate things and forget about it.