openapi: 3.0.2
info:
description: 'You can use this interface for trying out your Local REST API in Obsidian.
Before trying the below tools, you will want to make sure you press the "Authorize" button below and provide the API Key you are shown when you open the "Local REST API" section of your Obsidian settings. All requests to the API require a valid API Key; so you won''t get very far without doing that.
When using this tool you may see browser security warnings due to your browser not trusting the self-signed certificate the plugin will generate on its first run. If you do, you can make those errors disappear by adding the certificate as a "Trusted Certificate" in your browser or operating system''s settings.
'
title: Local REST API for Obsidian Active File API
version: '1.0'
servers:
- description: HTTPS (Secure Mode)
url: https://{host}:{port}
variables:
host:
default: 127.0.0.1
description: Binding host
port:
default: '27124'
description: HTTPS port
- description: HTTP (Insecure Mode)
url: http://{host}:{port}
variables:
host:
default: 127.0.0.1
description: Binding host
port:
default: '27123'
description: HTTP port
security:
- apiKeyAuth: []
tags:
- name: Active File
paths:
/active/:
delete:
parameters: []
responses:
'204':
description: Success
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: File does not exist.
'405':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: 'Your path references a directory instead of a file; this request method is valid only for updating files.
'
summary: 'Deletes the currently-active file in Obsidian.
'
tags:
- Active File
get:
description: 'Returns the content of the currently active file in Obsidian.
# Targeting a Sub-part of your Document
You can operate on a specific section of a note instead of the whole file by providing `Target-Type` and `Target` headers:
- Set `Target-Type` to `heading`, `block`, or `frontmatter`.
- Set `Target` to the name of the heading, block reference, or frontmatter field. If the target contains non-ASCII characters (e.g. accented letters), percent-encode the value (e.g. `H%C3%A9llo` for `Héllo`).
- For nested headings, use the `Target-Delimiter` header (default `::`) to separate levels.
You can also embed the target type and target directly in the URL path after the note identifier instead of using headers. The segment immediately following the note identifier is the target type, and the remaining segments form the target:
- `.../heading/My%20Section` is equivalent to supplying `Target-Type: heading` and `Target: My%20Section`.
- For nested headings, add additional path segments: `.../heading/My%20Section/Subsection` is equivalent to `Target: My%20Section::Subsection`.
- `.../frontmatter/fieldName` targets the `fieldName` frontmatter field.
- `.../block/abc123` targets the block with reference ID `abc123`.
When URL-embedded values are present they take priority over the corresponding headers.
# Retrieving Document Metadata
## Metadata
If you specify the header `Accept: application/vnd.olrapi.note+json`, will return a JSON representation of your note including parsed tag and frontmatter data as well as filesystem metadata.
## Document Map
If you specify the header `Accept: application/vnd.olrapi.document-map+json`, will return a JSON object outlining what PATCH targets exist. See "responses" below for details.
'
parameters:
- description: 'Type of sub-document section to target. When specified, the operation
applies only to the matching section rather than the whole file. Must
be used together with the `Target` header.
- `heading`: a markdown heading section.
- `block`: a block reference.
- `frontmatter`: a frontmatter field.
'
in: header
name: Target-Type
required: false
schema:
enum:
- heading
- block
- frontmatter
type: string
- description: 'The section to target; required when `Target-Type` is specified.
This value can be URL-Encoded and *must* be URL-Encoded if it
includes non-ASCII characters.
'
in: header
name: Target
required: false
schema:
type: string
- description: Delimiter used when specifying nested heading targets (e.g. "Heading 1::Subheading"). Defaults to "::".
in: header
name: Target-Delimiter
required: false
schema:
default: '::'
type: string
responses:
'200':
content:
application/json:
description: Returned when `Target-Type` is `frontmatter`; the JSON value of the specified frontmatter field.
schema: {}
application/vnd.olrapi.document-map+json:
schema:
properties:
blocks:
example:
- ^blockref1
- ^anotherBlockRef
items:
type: string
type: array
frontmatterFields:
example:
- title
- tags
- dateCreated
items:
type: string
type: array
headings:
example:
- Heading 1
- Heading 1::Subhead of Heading 1
- Heading 2
items:
type: string
type: array
type: object
application/vnd.olrapi.note+json:
schema:
$ref: '#/components/schemas/NoteJson'
text/markdown:
schema:
example: '# This is my document
something else here
'
type: string
description: Success
'404':
description: File or target section does not exist
summary: 'Return the content of the active file open in Obsidian.
'
tags:
- Active File
patch:
description: 'Inserts content into the currently-open note relative to a heading, block reference, or frontmatter field within that document.
Allows you to modify the content relative to a heading, block reference, or frontmatter field in your document.
> ![note]
> Note that this API was changed in Version 3.0 of this extension and the earlier PATCH API is now deprecated. Requests made using the previous version of this API will continue to work until Version 4.0 is released. See https://github.com/coddingtonbear/obsidian-local-rest-api/wiki/Changes-to-PATCH-requests-between-versions-2.0-and-3.0 for more details and migration instructions.
# How to Use & Examples
All of the below examples assume you have a document that looks like
this:
```markdown
---
alpha: 1
beta: test
delta:
zeta: 1
yotta: 1
gamma:
- one
- two
---
# Heading 1
This is the content for heading one
Also references some [[#^484ef2]]
## Subheading 1:1
Content for Subheading 1:1
### Subsubheading 1:1:1
### Subsubheading 1:1:2
Testing how block references work for a table.[[#^2c7cfa]]
Some content for Subsubheading 1:1:2
More random text.
^2d9b4a
## Subheading 1:2
Content for Subheading 1:2.
some content with a block reference ^484ef2
## Subheading 1:3
| City | Population |
| ------------ | ---------- |
| Seattle, WA | 8 |
| Portland, OR | 4 |
^2c7cfa
```
## Append, Prepend, or Replace Content Below a Heading
If you wanted to append the content "Hello" below "Subheading 1:1:1" under "Heading 1",
you could send a request with the following headers:
- `Operation`: `append`
- `Target-Type`: `heading`
- `Target`: `Heading 1::Subheading 1:1:1` (percent-encode any non-ASCII characters, e.g. `H%C3%A9llo` for `Héllo`)
- with the request body: `Hello`
The above would work just fine for `prepend` or `replace`, too, of course,
but with different results.
## Append, Prepend, or Replace Content to a Block Reference
If you wanted to append the content "Hello" below the block referenced by
"2d9b4a" above ("More random text."), you could send the following headers:
- `Operation`: `append`
- `Target-Type`: `block`
- `Target`: `2d9b4a`
- with the request body: `Hello`
The above would work just fine for `prepend` or `replace`, too, of course,
but with different results.
## Append, Prepend, or Replace a Row or Rows to/in a Table Referenced by a Block Reference
If you wanted to add a new city ("Chicago, IL") and population ("16") pair to the table above
referenced by the block reference `2c7cfa`, you could send the following
headers:
- `Operation`: `append`
- `Target-Type`: `block`
- `Target`: `2c7cfa`
- `Content-Type`: `application/json`
- with the request body: `[["Chicago, IL", "16"]]`
The use of a `Content-Type` of `application/json` allows the API
to infer that member of your array represents rows and columns of your
to append to the referenced table. You can of course just use a
`Content-Type` of `text/markdown`, but in such a case you''ll have to
format your table row manually instead of letting the library figure
it out for you.
You also have the option of using `prepend` (in which case, your new
row would be the first -- right below the table heading) or `replace` (in which
case all rows except the table heading would be replaced by the new row(s)
you supplied).
## Setting a Frontmatter Field
If you wanted to set the frontmatter field `alpha` to `2`, you could
send the following headers:
- `Operation`: `replace`
- `Target-Type`: `frontmatter`
- `Target`: `beep`
- with the request body `2`
If you''re setting a frontmatter field that might not already exist
you may want to use the `Create-Target-If-Missing` header so the
new frontmatter field is created and set to your specified value
if it doesn''t already exist.
You may find using a `Content-Type` of `application/json` to be
particularly useful in the case of frontmatter since frontmatter
fields'' values are JSON data, and the API can be smarter about
interpreting your `prepend` or `append` requests if you specify
your data as JSON (particularly when appending, for example,
list items).
## Identifying Patch Targets in a File
You can issue a GET request to `/vault/files/{path}` with an `Accept` header
of `application/vnd.olrapi.document-map+json` to get a JSON object
outlining what headings, block references, and frontmatter fields exist.
'
parameters:
- description: Patch operation to perform
in: header
name: Operation
required: true
schema:
enum:
- append
- prepend
- replace
type: string
- description: If the specified Target does not exist, create it?
in: header
name: Create-Target-If-Missing
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: If patch data already exists in Target, apply patch anyway?
in: header
name: Apply-If-Content-Preexists
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: Trim whitespace from Target content before applying the operation?
in: header
name: Trim-Target-Whitespace
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: 'Type of sub-document section to target. When specified, the operation
applies only to the matching section rather than the whole file. Must
be used together with the `Target` header.
- `heading`: a markdown heading section.
- `block`: a block reference.
- `frontmatter`: a frontmatter field.
'
in: header
name: Target-Type
required: true
schema:
enum:
- heading
- block
- frontmatter
type: string
- description: 'The section to target; required when `Target-Type` is specified.
This value can be URL-Encoded and *must* be URL-Encoded if it
includes non-ASCII characters.
'
in: header
name: Target
required: true
schema:
type: string
- description: Delimiter used when specifying nested heading targets (e.g. "Heading 1::Subheading"). Defaults to "::".
in: header
name: Target-Delimiter
required: false
schema:
default: '::'
type: string
requestBody:
content:
application/json:
schema:
example: '[''one'', ''two'']'
type: string
text/markdown:
schema:
example: '# This is my document
something else here
'
type: string
description: Content you would like to insert.
required: true
responses:
'200':
description: Success
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Bad Request; see response message for details.
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Does not exist
'405':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: 'Your path references a directory instead of a file; this request method is valid only for updating files.
'
summary: 'Partially update content in the currently open note.
'
tags:
- Active File
post:
description: 'Appends content to the end of the currently-open note.
# Targeting a Sub-part of your Document
You can operate on a specific section of a note instead of the whole file by providing `Target-Type` and `Target` headers:
- Set `Target-Type` to `heading`, `block`, or `frontmatter`.
- Set `Target` to the name of the heading, block reference, or frontmatter field. If the target contains non-ASCII characters (e.g. accented letters), percent-encode the value (e.g. `H%C3%A9llo` for `Héllo`).
- For nested headings, use the `Target-Delimiter` header (default `::`) to separate levels.
You can also embed the target type and target directly in the URL path after the note identifier instead of using headers. The segment immediately following the note identifier is the target type, and the remaining segments form the target:
- `.../heading/My%20Section` is equivalent to supplying `Target-Type: heading` and `Target: My%20Section`.
- For nested headings, add additional path segments: `.../heading/My%20Section/Subsection` is equivalent to `Target: My%20Section::Subsection`.
- `.../frontmatter/fieldName` targets the `fieldName` frontmatter field.
- `.../block/abc123` targets the block with reference ID `abc123`.
When URL-embedded values are present they take priority over the corresponding headers.
When a target is specified the content is appended within that section and the full updated file content is returned with a `200` status. Without a target, the content is appended to the end of the file and a `204` status is returned.
If you need `prepend` or `replace` operations, use `PATCH` instead.
'
parameters:
- description: If the specified Target does not exist, create it?
in: header
name: Create-Target-If-Missing
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: If patch data already exists in Target, apply patch anyway?
in: header
name: Apply-If-Content-Preexists
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: Trim whitespace from Target content before applying the operation?
in: header
name: Trim-Target-Whitespace
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: 'Type of sub-document section to target. When specified, the operation
applies only to the matching section rather than the whole file. Must
be used together with the `Target` header.
- `heading`: a markdown heading section.
- `block`: a block reference.
- `frontmatter`: a frontmatter field.
'
in: header
name: Target-Type
required: false
schema:
enum:
- heading
- block
- frontmatter
type: string
- description: 'The section to target; required when `Target-Type` is specified.
This value can be URL-Encoded and *must* be URL-Encoded if it
includes non-ASCII characters.
'
in: header
name: Target
required: false
schema:
type: string
- description: Delimiter used when specifying nested heading targets (e.g. "Heading 1::Subheading"). Defaults to "::".
in: header
name: Target-Delimiter
required: false
schema:
default: '::'
type: string
requestBody:
content:
text/markdown:
schema:
example: '# This is my document
something else here
'
type: string
description: Content you would like to append.
required: true
responses:
'200':
content:
text/markdown:
schema:
type: string
description: Success; targeted section updated. The full updated file content is returned.
'204':
description: Success; content appended to end of file.
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Bad Request
'405':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: 'Your path references a directory instead of a file; this request method is valid only for updating files.
'
summary: 'Append content to the active file open in Obsidian.
'
tags:
- Active File
put:
description: '# Targeting a Sub-part of your Document
You can operate on a specific section of a note instead of the whole file by providing `Target-Type` and `Target` headers:
- Set `Target-Type` to `heading`, `block`, or `frontmatter`.
- Set `Target` to the name of the heading, block reference, or frontmatter field. If the target contains non-ASCII characters (e.g. accented letters), percent-encode the value (e.g. `H%C3%A9llo` for `Héllo`).
- For nested headings, use the `Target-Delimiter` header (default `::`) to separate levels.
You can also embed the target type and target directly in the URL path after the note identifier instead of using headers. The segment immediately following the note identifier is the target type, and the remaining segments form the target:
- `.../heading/My%20Section` is equivalent to supplying `Target-Type: heading` and `Target: My%20Section`.
- For nested headings, add additional path segments: `.../heading/My%20Section/Subsection` is equivalent to `Target: My%20Section::Subsection`.
- `.../frontmatter/fieldName` targets the `fieldName` frontmatter field.
- `.../block/abc123` targets the block with reference ID `abc123`.
When URL-embedded values are present they take priority over the corresponding headers.
When a target is specified the target section is replaced with the request body and the full updated file content is returned with a `200` status. If the target does not exist it will be created. Without a target, the entire file is replaced and a `204` status is returned.
'
parameters:
- description: If patch data already exists in Target, apply patch anyway?
in: header
name: Apply-If-Content-Preexists
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: Trim whitespace from Target content before applying the operation?
in: header
name: Trim-Target-Whitespace
required: false
schema:
default: 'false'
enum:
- 'true'
- 'false'
type: string
- description: 'Type of sub-document section to target. When specified, the operation
applies only to the matching section rather than the whole file. Must
be used together with the `Target` header.
- `heading`: a markdown heading section.
- `block`: a block reference.
- `frontmatter`: a frontmatter field.
'
in: header
name: Target-Type
required: false
schema:
enum:
- heading
- block
- frontmatter
type: string
- description: 'The section to target; required when `Target-Type` is specified.
This value can be URL-Encoded and *must* be URL-Encoded if it
includes non-ASCII characters.
'
in: header
name: Target
required: false
schema:
type: string
- description: Delimiter used when specifying nested heading targets (e.g. "Heading 1::Subheading"). Defaults to "::".
in: header
name: Target-Delimiter
required: false
schema:
default: '::'
type: string
requestBody:
content:
'*/*':
schema:
type: string
text/markdown:
schema:
example: '# This is my document
something else here
'
type: string
description: Content of the file you would like to upload.
required: true
responses:
'200':
content:
text/markdown:
schema:
type: string
description: Success; targeted section replaced. The full updated file content is returned.
'204':
description: Success; entire file replaced.
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: 'Incoming file could not be processed. Make sure you have specified a reasonable file name, and make sure you have set a reasonable ''Content-Type'' header; if you are uploading a note, ''text/markdown'' is likely the right choice.
'
'405':
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: 'Your path references a directory instead of a file; this request method is valid only for updating files.
'
summary: 'Update the content of the active file open in Obsidian.
'
tags:
- Active File
components:
schemas:
NoteJson:
properties:
content:
type: string
frontmatter:
type: object
path:
type: string
stat:
properties:
ctime:
type: number
mtime:
type: number
size:
type: number
required:
- ctime
- mtime
- size
type: object
tags:
items:
type: string
type: array
required:
- tags
- frontmatter
- stat
- path
- content
type: object
Error:
properties:
errorCode:
description: 'A 5-digit error code uniquely identifying this particular type of error.
'
example: 40149
type: number
message:
description: Message describing the error.
example: A brief description of the error.
type: string
type: object
securitySchemes:
apiKeyAuth:
description: 'Find your API Key in your Obsidian settings
in the "Local REST API" section under "Plugins".
'
scheme: bearer
type: http