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
| Method | CLI Command | Description |
|---|---|---|
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 unresolved | All broken links in the vault. |
orphans() | obsidian orphans | Notes 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
Backlinks
const backs = await obsidian.linking.backlinks({ file: "Ideas/Feature.md" });
console.log('Backlinks:', backs);Outgoing Links
const outs = await obsidian.linking.outgoing({ file: "Ideas/Feature.md" });
console.log('Outgoing links:', outs);Unresolved Links
const broken = await obsidian.linking.unresolved();
console.log('Broken links:', broken);Orphan Notes
const orphanNotes = await obsidian.linking.orphans();
console.log('Orphans:', orphanNotes);Create a Link
await obsidian.linking.createLink({
file: "Ideas/Feature.md",
link: "ImplementationPlan"
});Create a New Note with a Link
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
unresolvedregularly to keep the graph healthy. - Use
orphansto discover isolated notes that may need linking or removal. - Prefer
createLinkfor incremental linking; usecreateNoteWithLinkfor scaffolding new content.