Sample code for 30+ languages & platforms
Zig

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.)

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const http = try chilkat.Http.init();
    defer http.deinit();
    http.setAuthToken("GMAIL-ACCESS-TOKEN");

    // The id of the GMail message to delete.
    const id = "1669cc9a926bb8c1";

    http.setUrlVar("userId", "me") catch {};
    http.setUrlVar("id", id) catch {};

    // Delete the email.
    const url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}";
    const response_str = http.quickDeleteStr(alloc, url) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("status = {d}\n", .{http.getLastStatus()});

    // 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.getLastStatus() != 204) {
        std.debug.print("{s}\n", .{response_str});
        std.debug.print("Failed.\n", .{});
        return;
    }

    std.debug.print("Message deleted!\n", .{});
}