Zig
Zig
Frame.io - Create a Folder
See more Frame.io Examples
Create a folder asset as a child to the root_asset_id.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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Implements the following CURL command:
// curl --request POST \
// --url https://api.frame.io/v2/assets/<root_asset_id>/children \
// --header 'authorization: Bearer <FRAME_IO_DEV_TOKEN>' \
// --header 'content-type: application/json' \
// --data '{"type":"folder", "name": "Folder at root"}'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "type": "folder",
// "name": "Folder at root"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("type", "folder") catch {};
json.updateString("name", "Folder at root") catch {};
http.setRequestHeader("content-type", "application/json");
// Adds the "Authorization: Bearer <FRAME_IO_DEV_TOKEN>" header.
http.setAuthToken("<FRAME_IO_DEV_TOKEN>");
// Our root_asset_id = 4ecb383f-71a8-4233-b665-d8f75136f554
// You'll need to modify the following line to use your root asset ID.
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://api.frame.io/v2/assets/4ecb383f-71a8-4233-b665-d8f75136f554/children", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "team_id": "95a5fbad-688d-46fc-aef1-2f011dd76c10",
// "public_item_count": 0,
// "properties": null,
// "deleted_at": null,
// "fps": null,
// "rating": null,
// "description": null,
// "updated_at": "2020-08-18T03:31:59.699011Z",
// "cover_asset_id": null,
// "archive_scheduled_at": null,
// "subtitle_tracks": null,
// "index": -7.0,
// "item_count": 0,
// "account_id": "b1cd046b-a3bf-4ef8-81a6-0afd74ecc455",
// "name": "FolderA",
// "checksums": null,
// "audio_tracks": null,
// "duration": null,
// "label": "none",
// "is_session_watermarked": false,
// "parent_id": "4ecb383f-71a8-4233-b665-d8f75136f554",
// "versions": 0,
// "project_id": "e76653c4-6cc0-4c47-936b-f7885b477dc0",
// "resource_id": null,
// "private": false,
// "frames": 0,
// "autoversion_id": null,
// "type": "folder",
// "uploaded_at": "2020-08-18T03:31:59.697174Z",
// "creator_id": "34b4f98a-7cc9-4159-8f46-c7c3d837fc6f",
// "user_permissions": {
// "can_download": true,
// "can_modify_template": false,
// "can_public_share_presentation": true,
// "can_public_share_review_link": true,
// "can_share_downloadable_presentation": true,
// "can_share_downloadable_review_link": true,
// "can_share_unwatermarked_presentation": true,
// "can_share_unwatermarked_review_link": true
// },
// "shared": false,
// "is_360": false,
// "_type": "folder",
// "comment_count": 0,
// "archived_at": null,
// "filetype": null,
// "id": "039845e8-bffe-4d6b-88d3-c780bae06342",
// "hard_deleted_at": null,
// "copy": false,
// "is_hls_required": false,
// "archive_status": null,
// "inserted_at": "2020-08-18T03:31:59.699011Z",
// "filesize": 0
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
_ = try j_resp.stringOf(alloc, "team_id");
_ = j_resp.intOf("public_item_count");
_ = try j_resp.stringOf(alloc, "properties");
_ = try j_resp.stringOf(alloc, "deleted_at");
_ = try j_resp.stringOf(alloc, "fps");
_ = try j_resp.stringOf(alloc, "rating");
_ = try j_resp.stringOf(alloc, "description");
_ = try j_resp.stringOf(alloc, "updated_at");
_ = try j_resp.stringOf(alloc, "cover_asset_id");
_ = try j_resp.stringOf(alloc, "archive_scheduled_at");
_ = try j_resp.stringOf(alloc, "subtitle_tracks");
_ = try j_resp.stringOf(alloc, "index");
_ = j_resp.intOf("item_count");
_ = try j_resp.stringOf(alloc, "account_id");
_ = try j_resp.stringOf(alloc, "name");
_ = try j_resp.stringOf(alloc, "checksums");
_ = try j_resp.stringOf(alloc, "audio_tracks");
_ = try j_resp.stringOf(alloc, "duration");
_ = try j_resp.stringOf(alloc, "label");
_ = j_resp.boolOf("is_session_watermarked");
_ = try j_resp.stringOf(alloc, "parent_id");
_ = j_resp.intOf("versions");
_ = try j_resp.stringOf(alloc, "project_id");
_ = try j_resp.stringOf(alloc, "resource_id");
_ = j_resp.boolOf("private");
_ = j_resp.intOf("frames");
_ = try j_resp.stringOf(alloc, "autoversion_id");
var v_type: [:0]const u8 = try j_resp.stringOf(alloc, "type");
_ = try j_resp.stringOf(alloc, "uploaded_at");
_ = try j_resp.stringOf(alloc, "creator_id");
_ = j_resp.boolOf("user_permissions.can_download");
_ = j_resp.boolOf("user_permissions.can_modify_template");
_ = j_resp.boolOf("user_permissions.can_public_share_presentation");
_ = j_resp.boolOf("user_permissions.can_public_share_review_link");
_ = j_resp.boolOf("user_permissions.can_share_downloadable_presentation");
_ = j_resp.boolOf("user_permissions.can_share_downloadable_review_link");
_ = j_resp.boolOf("user_permissions.can_share_unwatermarked_presentation");
_ = j_resp.boolOf("user_permissions.can_share_unwatermarked_review_link");
_ = j_resp.boolOf("shared");
_ = j_resp.boolOf("is_360");
v_type = try j_resp.stringOf(alloc, "_type");
_ = j_resp.intOf("comment_count");
_ = try j_resp.stringOf(alloc, "archived_at");
_ = try j_resp.stringOf(alloc, "filetype");
_ = try j_resp.stringOf(alloc, "id");
_ = try j_resp.stringOf(alloc, "hard_deleted_at");
_ = j_resp.boolOf("copy");
_ = j_resp.boolOf("is_hls_required");
_ = try j_resp.stringOf(alloc, "archive_status");
_ = try j_resp.stringOf(alloc, "inserted_at");
_ = j_resp.intOf("filesize");
}