Sample code for 30+ languages & platforms
Zig

Outlook -- Delete Folder

See more Outlook Examples

Deletes an email folder.

Note: This example requires Chilkat v9.5.0.68 or greater.

This example applies to: Exchange Online | Office 365 | Hotmail.com | Live.com | MSN.com | Outlook.com | Passport.com

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();

    // Use your previously obtained access token here:
    http.setAuthToken("MICROSOFT_GRAPH_ACCESS_TOKEN");

    // This example will delete the folder /Inbox/abc/subFolderC

    // Get the existing folder ID from the folder map created by this example
    const ht_folder_map = try chilkat.Hashtable.init();
    defer ht_folder_map.deinit();
    const sb_map = try chilkat.StringBuilder.init();
    defer sb_map.deinit();
    sb_map.loadFile("qa_data/outlook/folderMap.xml", "utf-8") catch {};
    ht_folder_map.addFromXmlSb(sb_map) catch {};

    const existing_folder_id = ht_folder_map.lookupStr(alloc, "/Inbox/abc/subFolderC") catch {
        std.debug.print("Folder ID not found\n", .{});
        return;
    };

    http.setUrlVar("folder_id", existing_folder_id) catch {};

    const resp = http.quickDeleteStr(alloc, "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}") catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // A 204 response (with no response body) indicates success.
    if (http.getLastStatus() == 204) {
        std.debug.print("Folder deleted.\n", .{});
    } else {
        std.debug.print("Folder not deleted.\n", .{});
        std.debug.print("{s}\n", .{resp});
    }
}