Sample code for 30+ languages & platforms
Zig

Delete a Task List

See more Google Tasks Examples

Demonstrates how to delete a Google task list.

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.

    // Get the previously obtained access token.
    // See Get Google Tasks Access Token.

    const fac = try chilkat.FileAccess.init();
    defer fac.deinit();
    const access_token = fac.readEntireTextFile(alloc, "qa_data/tokens/googleTasks.txt", "utf-8") catch {
        std.debug.print("{s}\n", .{try fac.getLastErrorText(alloc)});
        return;
    };

    const http = try chilkat.Http.init();
    defer http.deinit();

    http.setAuthToken(access_token);

    // Delete the task list with this ID:  MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6OTk5Njk3NjkxNzg4Nzg2NDow
    http.setUrlVar("taskListId", "MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6OTk5Njk3NjkxNzg4Nzg2NDow") catch {};

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("DELETE", "https://www.googleapis.com/tasks/v1/users/@me/lists/{$taskListId}", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // Show the response body. (empty for success)
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});

    // Examine the response status code. (204 = success)
    std.debug.print("response status code: {d}\n", .{resp.getStatusCode()});
}