IPWorks Cloud 2020 macOS Edition

Questions / Feedback?

DeleteMetadata Method

Deletes a metadata container from a resource.

Syntax

public func deleteMetadata(resourceId: String, scope: String, schema: String) throws -> Void

Remarks

This method deletes the metadata container specified by Scope and Schema from the resource specified by ResourceId. All metadata items held by the specified container are also deleted (individual metadata items can be deleted from a container using the UpdateMetadata method; refer to its documentation for more information).

Scope must be global or an enterprise-specific scope of the form enterprise_<EnterpriseId>. If Scope is empty, global is used.

If Scope is global, then Schema must be properties; otherwise, it must be the name of an existing metadata container schema owned by the enterprise identified in Scope. If Schema is empty, properties is used.

Metadata Notes

Box's Metadata architecture consists of two entities: metadata items, and metadata containers (which Box calls "metadata templates").

A metadata item is just a name-value pair held by a metadata container. Its name may be up to 256 characters long, cannot begin with the $ character, and must be unique within the container.

A metadata container holds metadata items, and is associated with a single resource. All metadata containers must be created using a metadata container schema, which describes the possible metadata items the container may hold. Containers are uniquely identified (per-resource) by a schema path like /Scope/Schema (ergo, a resource cannot have multiple containers of the same schema).

Box provides a general-use schema, /global/properties, that functions as an unrestricted key-value store that will accept any metadata item. Enterprises can also create custom schemas, /enterprise_<EnterpriseId>/Schema, that only allow predefined metadata items (with specific data types) to be added.

See the following methods for more information: CreateMetadata, ListMetadata, UpdateMetadata, and DeleteMetadata.

Note that metadata is only usable on resources owned by paid Box accounts.

string resId = "f:09876";

// Create an instance of the default metadata container ("/global/properties") with a couple of metadata 
// items in it, and associate it with the specified resource. (Note that we're assuming that the given
// resource doesn't already have an instance of the default metadata container associated with it.)
box.Metadata.Add(new BoxMetadata() { Name = "num1", Value = "123", ModOp = BoxMetadataModOps.opAdd });
box.Metadata.Add(new BoxMetadata() { Name = "text1", Value = "abc", ModOp = BoxMetadataModOps.opAdd });

// All of the class's metadata-related methods all empty string to be passed to their Scope and Schema
// parameters, in which case "global" and "properties" will be used, respectively. (The exception is the
// ListMetadata() method, which interprets empty Scope and Schema values in a different way; refer to the
// ListMetadata() documentation for more information.)
box.CreateMetadata(resId, "", "");

// Some time later, imagine you wish to update the metadata items held by the default container on that
// resource. Always call ListMetadata() first so that class has the latest metadata loaded.
box.ListMetadata(resId, "global", "properties");

// Now that the class has the latest metadata items loaded for the default container on the given
// resource, we can modify what we wish to, setting the ModOp fields appropriately.
box.Metadata[0].Value = "456"; // Update the value of the "num1" item.
box.Metadata[0].ModOp = BoxMetadataModOps.opReplace;
box.Metadata[1].ModOp = BoxMetadataModOps.opRemove; // Remove the "text1" item.
// Add a new "text2" item.
box.Metadata.Add(new BoxMetadata() { Name = "text2", Value = "def", ModOp = BoxMetadataModOps.opAdd });

// Now commit the updates. Our example performs very simple updates, but you can build a very complex
// update scenario using some of the other ModOp values. Refer to the UpdateMetadata() documentation
// for more information.
box.UpdateMetadata(resId, "", "");

// Finally, this will remove the entire default metadata container from the given resource.
box.DeleteMetadata(resId, "", "");

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 macOS Edition - Version 20.0 [Build 8265]