Obsidian SDK
Core APIs

Linking

Query backlinks, outgoing links, find orphans, and manage the knowledge graph.

Linking Module

Overview

The Linking module provides programmatic access to Obsidian's graph‑related CLI commands: backlinks, links, unresolved, orphans, create, and create-note.

Quick Start

const backlinks = await obsidian.linking.backlinks({ file: "Project/Plan.md" });
console.log(backlinks);

Usage

MethodCLI CommandDescription
backlinks(input)obsidian backlinks file=…Notes that link to the given file.
outgoing(input)obsidian links file=…Notes that the given file links to.
unresolved()obsidian unresolvedAll broken links in the vault.
orphans()obsidian orphansNotes with no inbound links.
createLink(input)obsidian append file=… content=[[link]]Appends a wikilink.
createNoteWithLink(input)obsidian create path=… content=…Creates a new note with a link.

Examples

const backs = await obsidian.linking.backlinks({ file: "Ideas/Feature.md" });
console.log('Backlinks:', backs);
const outs = await obsidian.linking.outgoing({ file: "Ideas/Feature.md" });
console.log('Outgoing links:', outs);
const broken = await obsidian.linking.unresolved();
console.log('Broken links:', broken);

Orphan Notes

const orphanNotes = await obsidian.linking.orphans();
console.log('Orphans:', orphanNotes);
await obsidian.linking.createLink({
  file: "Ideas/Feature.md",
  link: "ImplementationPlan"
});
await obsidian.linking.createNoteWithLink({
  path: "Projects/NewProject.md",
  link: "Ideas/Feature.md",
  content: "# New Project\nThis project relies on the Feature note."
});

Error Handling

try {
  await obsidian.linking.backlinks({ file: "Nonexistent.md" });
} catch (e) {
  console.error('Backlinks failed:', e.message);
}

Best Practices

  • Run unresolved regularly to keep the graph healthy.
  • Use orphans to discover isolated notes that may need linking or removal.
  • Prefer createLink for incremental linking; use createNoteWithLink for scaffolding new content.

On this page