7.4 KiB
Mochi API Reference
This document provides detailed reference information for the Mochi.cards API.
Authentication
Mochi uses HTTP Basic Auth with your API key as the username (no password needed).
To get your API key:
- Open Mochi app
- Go to Account Settings
- Find the API Keys section
Set the API key as an environment variable:
export MOCHI_API_KEY="your_api_key_here"
Base URL
https://app.mochi.cards/api/
Data Formats
The API supports both JSON and transit+json. This skill uses JSON for simplicity.
Pagination
List endpoints return paginated results with:
docs: Array of itemsbookmark: Cursor for next page (may be present even if no more pages exist)
Cards
Card Structure
Cards contain:
id: Unique identifiercontent: Markdown contentdeck-id: Parent deck IDtemplate-id: Optional template IDfields: Map of field IDs to values (when using templates)tags: Set of tags extracted from contentmanual-tags: Set of tags added manuallyarchived?: Boolean indicating archived statustrashed?: Timestamp if trashed (soft delete)review-reverse?: Whether to review in reversepos: Lexicographic position for sortingcreated-at: Creation timestampupdated-at: Last modification timestampreviews: Array of review historyreferences: Set of references to other cards
Card Content
Card content is markdown with some special features:
---creates a card side separator (for multi-sided cards)@[title](url)creates references to other cards or external linksembeds attachments#tagadds tags inline<< Field name >>in templates gets replaced by field values
Positioning Cards
The pos field determines card order within a deck using lexicographic sorting:
- If card A has
posof"6"and card B hasposof"7" - To insert between them, use
posof"6V"(any string between "6" and "7") - Common pattern: use letters like
"a","b","c"for initial cards, then insert with decimals or additional letters
Card Attachments
Attachments can be added to cards using multipart/form-data:
- POST
/cards/{card-id}/attachments/{filename} - DELETE
/cards/{card-id}/attachments/{filename}
Attachments are referenced in card content using @media/ syntax.
Decks
Deck Structure
Decks contain:
id: Unique identifiername: Deck nameparent-id: Optional parent deck for nestingsort: Numeric sort order (decks sorted by this number)archived?: Boolean indicating archived statustrashed?: Timestamp if trashed (soft delete)sort-by: How cards are sorted in the deckcards-view: How cards are displayedshow-sides?: Whether to show all card sidessort-by-direction: Boolean to reverse sort orderreview-reverse?: Whether to review cards in reverse
Sort-by Options
How cards are sorted within the deck:
none: Manual ordering (usingposfield)lexicographicallyorlexigraphically: Alphabetically by namecreated-at: By creation dateupdated-at: By last modification dateretention-rate-asc: By retention rate (ascending)interval-length: By review interval length
Cards-view Options
How cards are displayed in the deck:
list: Traditional list viewgrid: Grid/tile layoutnote: Note-taking viewcolumn: Column layout
Deck Hierarchy
Decks can be nested using the parent-id field to create organizational hierarchies.
Templates
Template Structure
Templates define card structure using fields:
id: Unique identifiername: Template name (1-64 characters)content: Markdown with field placeholderspos: Lexicographic position for sortingfields: Map of field definitionsstyle: Visual styling optionsoptions: Template behavior options
Field Placeholders
In template content, use << Field name >> to insert field values.
Field Types
Available field types:
text: Simple text inputboolean: True/false checkboxnumber: Numeric inputdraw: Drawing/sketch inputai: AI-generated contentspeech: Speech/audio recordingimage: Image uploadtranslate: Translation fieldtranscription: Audio transcriptiondictionary: Dictionary lookuppinyin: Chinese pinyinfurigana: Japanese reading aid
Field Definition Structure
Each field is defined as:
{
"id": "field-id",
"name": "Display Name",
"type": "text",
"pos": "a",
"content": "Default or instruction text",
"options": {
"multi-line?": true,
"hide-term": false
}
}
Common Field Options
multi-line?: Allow multi-line text inputhide-term: Hide the term in certain viewsai-task: Instructions for AI-generated fields- Various type-specific options
Template Style Options
{
"text-alignment": "left" // or "center", "right"
}
Template Options
{
"show-sides-separately?": false // Show template sides separately during review
}
Example Template
Basic flashcard template:
{
"name": "Basic Flashcard",
"content": "# << Front >>\\n---\\n<< Back >>",
"fields": {
"front": {
"id": "front",
"name": "Front",
"type": "text",
"pos": "a"
},
"back": {
"id": "back",
"name": "Back",
"type": "text",
"pos": "b",
"options": {
"multi-line?": true
}
}
}
}
Common Patterns
Creating Simple Flashcards
For simple flashcards, use markdown content with --- separator:
# Question here
---
Answer here
Creating Template-Based Cards
- First retrieve or create a template
- Get the field IDs from the template
- Create card with field values matching the template structure
Batch Operations
To create multiple cards:
- List existing decks to get deck ID
- Loop through content items
- Create cards one at a time (API doesn't support batch creation)
Organizing with Tags
Tags can be added two ways:
- Inline in content:
#python #programming - Using
manual-tagsfield:["python", "programming"](without # prefix)
Manual tags are useful when you want tags separate from content.
Soft Delete vs Hard Delete
- Soft delete: Set
trashed?to current ISO 8601 timestamp - Hard delete: Use DELETE endpoint (permanent, cannot be undone)
Soft delete is recommended for safety.
Error Handling
HTTP Status Codes:
2xx: Success4xx: Client error (missing parameters, validation failure, not found)5xx: Server error (rare)
Error responses include:
{
"errors": {
"field-name": "Error message for this field"
}
}
Or for general errors:
{
"errors": ["Error message"]
}
Rate Limiting
The API documentation doesn't specify rate limits, but follow good practices:
- Don't make excessive requests in short periods
- Implement exponential backoff on errors
- Cache deck/template lists when possible
Best Practices
- Use Templates: For consistent card structure, create templates
- Organize with Decks: Create hierarchical deck structures
- Tag Consistently: Use consistent tag naming conventions
- Soft Delete First: Use trashed? instead of permanent deletion
- Position Strategically: Use the
posfield for custom ordering - Validate Content: Check markdown syntax before creating cards
- Handle Pagination: Always check for and handle
bookmarkin list responses - Store IDs: Keep track of deck and template IDs for reuse