Skip to main content

Node Metadata and Tags

Node metadata and tags allow you to add custom information and labels to nodes for better organization and management.

Overview

Node metadata and tags in RainMaker enable you to:

  • Attach tags to nodes for categorization
  • Update and manage node metadata
  • Remove tags and metadata when needed

Attach Tags

Attach tags to a node using the attachTags method.

try {
const tags = ["living-room", "smart-lighting", "priority"];
const response = await node.attachTags(tags);
console.log("Tags attached successfully:", response);
} catch (error) {
console.error("Error attaching tags:", error);
}

Remove Tags

Remove tags from a node using the removeTags method.

try {
const response = await node.removeTags();
console.log("Tags removed successfully:", response);
} catch (error) {
console.error("Error removing tags:", error);
}

Update Metadata

Update metadata associated with a node using the updateMetadata method.

try {
const metadata = {
location: "Living Room",
installationDate: "2024-01-15",
notes: "Main lighting control"
};

const response = await node.updateMetadata(metadata);
console.log("Metadata updated successfully:", response);
} catch (error) {
console.error("Error updating metadata:", error);
}

Delete Metadata

Delete metadata associated with a node using the deleteMetadata method.

try {
const response = await node.deleteMetadata();
console.log("Metadata deleted successfully:", response);
} catch (error) {
console.error("Error deleting metadata:", error);
}

Example: Managing Tags and Metadata

try {
const response = await userInstance.getUserNodes();
const node = response.nodes[0];

// Attach tags
await node.attachTags(["smart-home", "lighting"]);

// Update metadata
await node.updateMetadata({
room: "Bedroom",
deviceType: "Smart Light"
});

// Access tags and metadata
console.log("Node tags:", node.tags);
console.log("Node metadata:", node.metadata);
} catch (error) {
console.error("Error managing tags and metadata:", error);
}

On this page