Sample code for 30+ languages & platforms
Zig

Delete a Google Calendar Event

See more Google Calendar Examples

Demonstrates how to delete a Google Calendar event.

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.

    // This example uses a previously obtained access token having permission for the
    // Google Calendar scope.

    // In this example, Get Google Calendar OAuth2 Access Token, the access
    // token was saved to a JSON file.  This example fetches the access token from the file..
    const json_token = try chilkat.JsonObject.init();
    defer json_token.deinit();
    try json_token.loadFile("qa_data/tokens/googleCalendar.json");
    if (!json_token.hasMember("access_token")) {
        std.debug.print("No access token found.\n", .{});
        return;
    }

    const http = try chilkat.Http.init();
    defer http.deinit();
    http.setAuthToken(try json_token.stringOf(alloc, "access_token"));

    // Your URL should use the actual calendar ID and the actual event ID for the event to be deleted.
    const url = "https://www.googleapis.com/calendar/v3/calendars/your_calendar_id/events/your_event_id";

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("DELETE", url, resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    if (resp.getStatusCode() == 204) {
        // Success.
        std.debug.print("Event deleted\n", .{});
    } else {
        if (resp.getStatusCode() == 401) {
            std.debug.print("Try refreshing the access token and then retry...\n", .{});
        }

        // Failed.
        std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
    }
}