JavaScript
JavaScript
Permanently Delete a Specific GMail Message
See more GMail REST API Examples
Immediately and permanently deletes the specified message. This operation cannot be undone. (This is not the same as moving a message to Trash.)
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new CkHttp();
http.AuthToken = "GMAIL-ACCESS-TOKEN";
// The id of the GMail message to delete.
var id = "1669cc9a926bb8c1";
var userId = "me";
http.SetUrlVar("userId","me");
http.SetUrlVar("id",id);
// Delete the email.
var url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}";
var responseStr = http.QuickDeleteStr(url);
if (http.LastMethodSuccess !== true) {
console.log(http.LastErrorText);
return;
}
console.log("status = " + http.LastStatus);
// A 204 response indicate success.
// It is common for HTTP DELETE operations to respond with a 204 status code with an empty body for success.
// You'll find many REST APIs follow this custom..
if (http.LastStatus !== 204) {
console.log(responseStr);
console.log("Failed.");
return;
}
console.log("Message deleted!");