Drafts Actions for Creating Anki Cards

Does anyone have any suggestions for actions to create Anki Cards from content in Drafts?

I saw a post about sending content from iBooks to Anki via Drafts, but they were looking for a tweak and didn’t describe the action they use - just that they use an x-url-callback.

I’m not looking to pull content from iBooks specifically, just the general approach for creating cards with content that’s already in Drafts, or the general approach/code for sending content through Drafts from other apps.

Thanks in advance for any help you can be.

I found this post in the forums. It seems like Anki posting would rely on URL schemes but the thread looks to have sorted through it. Have a look and see if this answers your question, otherwise I’ll take a look a bit later.

I should add that this only seems to work from the Mobile Anki app though. When I tested briefly with the desktop version, the URL scheme didn’t seem to get picked up.

Here is my setup:

I have different Drafts actions to create anki cards.

This allows me to:

  • add content to different decks and notetypes
  • add specific tags for organising the Anki notes
  • add generic content to Anki notes

Each action has only one step: Callback URL. In my case, the template looks like this:

anki://x-callback-url/addnote?profile=User%201&type=Einfach&deck=Medizin&fldVorderseite=[[title]]&fldR%C3%BCckseite=[[body]]&tags=staging

Everything in bold is user specific for your Anki setup:

  • profile
  • note type (here: Einfach)
  • deck name (here: Medizin)
  • first fieldname (here: Vorderseite, for “front side”)
  • second fieldname (here R%C3%BCckseite, the encoded form of Rückseite, meaning “back side”
  • one or more tags (staging)

Documentation for AnkiMobile’s URL Scheme: URL Schemes - AnkiMobile Manual (it does not work on Anki for Windows/Mac/Linux).

I usually prepare drafts with a first line that is passed into Anki as [[title]] and the remaining content passed into Anki as [[body]].

Every Anki note created from Drafts contains the tag staging, so I can rework these notes in Anki if needed and remove the tag afterwards.

You can add several tags at once:

&tags=staging%20Englisch%20Wortart::Phrase

adds the tags

  • staging
  • Englisch
  • as a hierarchical tag Wortart::Phrase

I only need to remove the tag staging in Anki, every other tagging is done from Drafts.

You can also use Drafts actions to add generic content to your Anki cards. For example, I sometimes stumble across drug trade names I don’t know. So I make a draft containing

Hygroton
chlortalidone

After applying

anki://x-callback-url/addnote?profile=User%201&type=Einfach&deck=Medizin&fldVorderseite=Welcher%20Wirkstoff%20ist%20[[title]]%3f&fldR%C3%BCckseite=[[body]]&tags=staging%20Medizin::Pharmakologie

I get an Anki card prompting me

Which drug is Hygroton? (German: Welcher%20Wirkstoff%20ist%20[[title]]%3f)

with the answer chlortalidone and a pharmacology tag already set.

You can certainly do more with Drafts and Anki. For example, instead of multiple actions with different tags, only one action and a selection list of which tags should be used.

1 Like

Thanks so much for finding this. Will play with it this weekend and let you know if I need more help.

The good news is, I only use Drafts of my iPhone & iPad, so if this works, I’ll be good to go.

Thanks again for getting back to me so quickly.

Hi CMx3,

I finally got around to trying this, but am clearly missing something.

Here’s the information I put into the Callback URL:

Profile: User 1
Note Type: Basic
Deck Name: Misc
First Field Name: Front
Second Field Name: Back
Tag: crypto

So I created a new action and added the following step and a Call back URL:

anki://x-callback-url/addnote?profile=User%1&type=Basic&deck=Misc&fldFront=[[title]]&fldBack=[[body]]&tags=crypto

In Drafts I entered:

Anki Test
Did this work?

So if I understand this correctly, Anki Test should appear on the front of the card, and Did this work, should appear on the back of the card.

But when I run the action in Drafts, I get the following error message:

Callback URL Error

Invalid URL in generated by Callback URL step template.

What am I doing wrong?

Hi, try

anki://x-callback-url/addnote?profile=User%201&type=Basic&deck=Misc&fldFront=[[title]]&fldBack=[[body]]&tags=crypto

(For the space).

Can you type out the whole action? Or Link to one of it’s there in the action groups? This is very useful. Thanks

Thanks so much! Works like a charm! Off to tinker to see how best I can use this … :slight_smile:

Thanks for replying. The good news is that, thanks to CMx3, I’m all set.

@agiletortoise Did the last two updates (40.0 and 40.0.1) touch anything related to the x-callback-url scheme? My actions open Anki but nothing happens there anymore and the view doesn’t change back to Drafts. It broke after iOS 17/Drafts updates.

Nothing has changed on our end.

If you end up in Anki and nothing happens, it seems likely something change/broke at their end.

The best way to test would be to construct a URL for Anki as an example based on some of the examples above, and open it in Safari to see if it works as expected.