Zig
Zig
Move a GMail Message to Trash
See more GMail REST API Examples
Moves a specific GMail email message to trash.Chilkat Zig Downloads
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 move to Trash.
const id = "16678c485e7f0a0c";
http.setUrlVar("userId", "me") catch {};
http.setUrlVar("id", id) catch {};
// Move to trash by POSTing w/ an empty request body.
const url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}/trash";
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("POST", url, "", "", "", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("status = {d}\n", .{resp.getStatusCode()});
// A 200 response status indicate success.
if (resp.getStatusCode() != 200) {
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// A successful repsonse contains JSON that looks like this:
// {
// "id": "16678c485e7f0a0c",
// "threadId": "16678c485e7f0a0c",
// "labelIds": [
// "TRASH",
// "CATEGORY_SOCIAL"
// ]
// }
std.debug.print("response body:\n", .{});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
std.debug.print("Message moved to trash!\n", .{});
}