The Mochi API is organized around REST. It accepts JSON or transit+json encoded request bodies and returns either json or transit+json encoded responses. When making requests with JSON, keyword parameters must be sent as strings.
Base URL:
https://app.mochi.cards/api/
Authentication
Mochi uses API Keys to authenticate requests. You can view and manage your API Keys in the Account Settings window within the app.
Authentication to the API is performed via HTTP Basic Auth. Provide your API key as the basic auth username value. You do not need to provide a password.
curl https://app.mochi.cards/api/decks -u my_api_key:
# The colon prevents curl from asking for a password.
Tip
Basic auth credentials must be base64 encoded. Run the above cURL command with -v to see the base64 encoded version of your API key.
Pagination
Some requests return a list of resources. The response will be an object with a docs property and a bookmark property. The docs property will contain alist of the documents, and the bookmark property can be used in subsequent requests to fetch the next logical page of the collection. Not every request that returns a bookmark has additional pages.
Mochi uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, a document was not found, etc.). Codes in the 5xx range indicate an error with Mochi's servers (these are rare).
In most cases the API will also return a JSON or Transit response with more information about the error. In the case of validation errors, there will be a key corresponding to each field that failed validation.
Example error responses:
500 { "errors" ["Something went wrong!"] }
403 { "errors" ["Please upgrade to use this feature."] }
422 { "errors" { "content": ":content field cannot be nil." } }
Rate limits
The Mochi API uses rate limit to protect against bursts of traffic and help maximize stability. If you send many requests in quick succession, you might see error responses with status code 429.
Concurrency limiter
The concurrency limiter restricts the number of concurrent active requests. Currently API calls are limited to one concurrent request per account. You must wait for the previous request to return before issuing a new request.
Cards
Endpoints:
GET /cards -- List cards
POST /cards -- Create a card
GET /cards/:id -- Retrieve a card
POST /cards/:id -- Update a card
DELETE /cards/:id -- Delete a card
Create a card
POST https://app.mochi.cards/api/cards/
Cards can be created one at a time. Cards can be stored in a deck and can contain markdown content.
Parameters
contentrequired
string - The markdown content of the card.
deck-idrequired
keyword - The deck ID that the card belongs too.
template-idoptional
keyword - The ID of the template to use for this card.
archived?optional
boolean - Whether the card is archived or not.
review-reverse?optional
boolean - Whether the card should also be reviewed in reverse order (bottom to top).
posoptional
string - The relative position of the card within the deck. Cards are sorted lexicographically by the value of this attribute. For example if card A has a :pos of "6" and card B has a :pos of "7", you can create a new card in between them by setting its :pos to "6V".
manual-tagsoptional
set of strings - A set (or an array in JSON) of tags to add to the card. Use this when you want to attach tags to a card without adding them to the content of the card. Tags should not include the initial # character.
fieldsoptional
map - A map of field IDs (keyword) to field values. If the fields attribute is present, the content field can be left blank (it will be ignored when the card is rendered). The field IDs should correspond to the fields defined on the template used by the card. Fields can be displayed within a template using the following syntax: << Field name >>. Each value in the map is another map with the following structure:
idrequired keyword - The ID of the field. Should be the same as the key for this value.
valuerequired string - The value to be used for this field on this card.
This will return the created card if successful. Will return an error if something goes wrong, usually if required parameters are missing, or if supplied parameters fails validation.
Retrieve a card
GET https://app.mochi.cards/api/cards/:card-id
Retrieves a card that already exists. The returned data will look identical to the data returned from the card creation request.
Parameters
No parameters.
Example request
GET https://app.mochi.cards/api/cards/btmZUXWM
Accept: application/json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
Lists cards in pages of 10 cards per page. Use the bookmark attribute to request the next page. Optionally specific a deck-id to fetch only cards for that deck.
Parameters
deck-idoptional string - Only return cards for the deck specified by this deck ID.
limitoptional number - The number of cards to return per page. The limit can range from 1 and 100, and the default is 10.
bookmarkoptional string - A cursor for use in pagination. Returned from a previous list request that has additional documents.
Example request
# Without a bookmark
GET https://app.mochi.cards/api/cards/
# With a bookmark
GET https://app.mochi.cards/api/cards?bookmark=some-bookmark
# With a deck-id
GET https://app.mochi.cards/api/cards?deck-id=my-deck-id
Returns
A dictionary with a docs property that contains an array of up to limit cards, and a bookmark property that can be used to fetch the next page of results.
Updating a card accepts most of the same parameters as creating a card. The ID of the card must be passed in as part of the URL.
Parameters
contentoptional string - The markdown content of the card.
deck-idoptional keyword - The deck ID that the card belongs too.
template-idoptional keyword - The ID of the template to use for this card.
archived?optional boolean - Whether the card is archived or not.
trashed?optional timestamp - Whether the card is in the trash or not. Timestamps should be ISO 8601 format, matching javascript's Date#toJSON method.
review-reverse?optional boolean - Whether the card should also be reviewed in reverse order (bottom to top).
posoptional string - The relative position of the card within the deck. Cards are sorted lexicographically by the value of this attribute. For example if card A has a :pos of "6" and card B has a :pos of "7", you can create a new card in between them by setting its :pos to "6V".
manual-tagsoptional set of strings - A set (or an array in JSON) of tags to add to the card. Use this when you want to attach tags to a card without adding them to the content of the card. Tags should not include the initial # character. Setting this will overwrite whatever value for this field was already set on the card.
fieldsoptional map - A map of field IDs (keyword) to field values. The field IDs should correspond to the fields defined on the template used by the card. Fields can be displayed within a template using the following syntax: << Field name >>. Each value in the map is another map with the following structure:
idrequired keyword - The ID of the field. Should be the same as the key for this value.
valuerequired string - The value to be used for this field on this card.
Example request
POST https://app.mochi.cards/api/cards/00UlY4dd
Content-Type: application/json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
{
"content": "New card from API. ",
"deck-id": "btmZUXWM",
"review-reverse?": false,
"archived?": false,
"pos": "6V",
"manual-tags": ["philosophy", "philosophy/aristotle"]
}
POST https://app.mochi.cards/api/cards/00UlY4dd
Content-Type: application/transit+json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
{
"~:content": "New card from API. ",
"~:deck-id": "~:btmZUXWM",
"~:review-reverse?": false,
"~:archived?": false,
"~:pos": "6V",
"~:tags": {"~#set": ["philosophy", "philosophy/aristotle"]}
}
Delete a card
DELETE https://app.mochi.cards/api/cards/:card-id
Permanently deletes a card and its attachments.
Warning
This action cannot be undone. For a "soft" deletion you can update a card and set its trashed? property to the current time (as an ISO 8601 timestamp).
Decks are the containers of cards. They can also contain other nested decks. Various properties can be set on a deck to control how cards a reviewed, and how the cards are displayed on the deck page.
Endpoints:
GET /decks -- List decks
POST /decks -- Create a deck
GET /decks/:id -- Retrieve a deck
POST /decks/:id -- Update a deck
DELETE /decks/:id -- Delete a deck
Create a deck
POST http://localhost:8090/api/decks/
Decks fundamentally act as collections of cards. In addition to cards, decks can also contain other decks to create heirarchies of content. There are also a number of properties on the deck that control how cards are displayed and reviewd.
Parameters
namerequired string - A string representing the name of the deck.
parent-idoptional keyword - The ID of a parent deck to nest this deck under.
sortoptional integer - Decks are sorted numerically based on this number.
trashed?optional timestamp - Whether the deck is in the trash or not. Cards and child decks within a trashed deck will also be effectively trashed. Timestamps should be ISO 8601 format, matching javascript's Date#toJSON method.
archived?optional boolean - Whether the deck is archived. Cards in archived will not show up as new cards or be due for review.
sort-byoptional keyword - Determines how cards are sorted on the deck page. Does not effect reviews or new card learning order. One of :none :lexigraphically :lexicographically :created-at :updated-at :retention-rate-asc :interval-length
cards-viewoptional keyword - Determined how cards will be displayed on the deck page. One of :list :grid :note :column.
show-sides?optional boolean - Whether or not to show all sides of a card on the deck page or not.
sort-by-directionoptional boolean - When true cards sort order will be reversed.
review-reverse?optional boolean - Whether or not to reveal the sides of a cards in the deck in reverse order or not (bottom to top) in addition to the normal order (top to bottom).
Example request
POST http://localhost:8090/api/decks/
Content-Type: application/json
Accept: application/json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
{
"name": "My new deck",
"parent-id": "HJBMBGBO",
"sort": 1,
"archived?": true,
"trashed?": "2012-04-23T18:25:43.511Z",
"show-sides?": true,
"sort-by-direction": true,
"review-reverse?": true
}
nameoptional string - A string representing the name of the deck.
parent-idoptional keyword - The ID of a parent deck to nest this deck under.
sortoptional integer - Decks are sorted numerically based on this number.
trashed?optional timestamp - Whether the deck is in the trash or not. Cards and child decks within a trashed deck will also be effectively trashed. Timestamps should be ISO 8601 format, matching javascript's Date#toJSON method.
archived?optional boolean - Whether the deck is archived. Cards in archived will not show up as new cards or be due for review.
sort-byoptional keyword - Determines how cards are sorted on the deck page. Does not effect reviews or new card learning order. One of :none :lexigraphically :lexicographically :created-at :updated-at :retention-rate-asc :interval-length
cards-viewoptional keyword - Determined how cards will be displayed on the deck page. One of :list :grid :note :column.
show-sides?optional boolean - Whether or not to show all sides of a card on the deck page or not.
sort-by-directionoptional boolean - When true cards sort order will be reversed.
review-reverse?optional boolean - Whether or not to reveal the sides of a cards in the deck in reverse order or not (bottom to top) in addition to the normal order (top to bottom).
Example request
POST https://app.mochi.cards/api/decks/RMb5BZ67
Content-Type: application/json
Accept: application/json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
{
"name": "My new deck",
"parent-id": "HJBMBGBO",
"sort": 1,
"archived?": true,
"trashed?": "2012-04-23T18:25:43.511Z",
"show-sides?": true,
"sort-by-direction": true,
"review-reverse?": true
}
Templates can be applied to decks and / or cards. Templates allow you to render content to cards using fields.
Endpoints:
GET /templates -- List templates
POST /templates -- Create a template
GET /templates/:id -- Retrieve a template
Create a template
POST https://app.mochi.cards/api/templates/
Templates define the structure and layout for cards using field placeholders. Templates can contain markdown content and field references that get populated with card-specific data.
TIP: You can use the "Retrieve a template" endpoint to examine the structure of an existing template and use that as the basis for creating a new one.
Parameters
namerequired string - The name of the template (1-64 characters).
contentrequiredstring - The markdown content of the template with field placeholders like << Field name >>.
posoptional string - The relative position of the template for sorting. Templates are sorted lexicographically by this value.
fieldsrequiredmap - A map of field IDs (keyword) to field definitions. Each field defines how content should be input and processed. Each field is a map with the following structure:
idrequired keyword - The ID of the field. Should be the same as the key for this field.
nameoptional string - The human-readable name for this field.
typeoptional keyword - The field type. One of :text :boolean :number :draw :ai :speech :image :translate :transcription :dictionary :pinyin :furigana.
posoptional string - The relative position for sorting fields within the template.
contentoptional string - Default content or instructions for this field.
optionsoptional map - Field-specific options like :multi-line?, :hide-term, :ai-task, etc.
styleoptional map - Styling options for the template:
text-alignmentoptional keyword - Text alignment. One of :left :center :right.
optionsoptional map - Template-level options:
show-sides-separately?optional boolean - Whether to show template sides separately during review.
:bookmarkoptional string - A cursor for use in pagination. Returned from a previous list request that has additional documents.
Example request
# Without a bookmark
GET https://app.mochi.cards/api/templates/
# With a bookmark
GET https://app.mochi.cards/api/templates?bookmark=somebookmarkgoeshere
You can query for cards that are due on a specified date.
Endpoints:
GET /due -- List cards due on some date
GET /due/:deck-id -- List cards due on some date for a given deck
Get all due cards
POST https://app.mochi.cards/api/templates/
Templates define the structure and layout for cards using field placeholders. Templates can contain markdown content and field references that get populated with card-specific data.
TIP: You can use the "Retrieve a template" endpoint to examine the structure of an existing template and use that as the basis for creating a new one.
Parameters
dateoptional timestamp - The date that the returned cards are due. If omitted it will use today's date. Timestamps should be ISO 8601 format, matching javascript's Date#toJSON method.
Example request
GET https://app.mochi.cards/api/due/
Accept: application/json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
GET https://app.mochi.cards/api/due/
Accept: application/transit+json
Authorization: Basic NDZiYjA4YTY5ODAzNmFiMjk3MjU4ZWFlOg==
Returns
Returns a list of cards that are due on the given date.