Suggest add ankimobile url schema to get note fields

Hi ankimobile dev team:
I am a co-author of an ankimobile assist app named “ankiclip” which can be used to add note into ankimobile by one clicking in iOS app(like native BBC app)

To do this, we used ankimobile url schema. But currently our users have to manually type those fields in app setting

Is there anyway from ankimobile to add some url schema. So it can let us retrieve these info automatically, list it in drop down list, then users can select from list and never wrongly typed these fields name, for example:

  1. anki://x-callback-url/getprofiles
  2. anki://x-callback-url/getnotes?profile={profilename}
  3. anki://x-callback-url/gettemplate?profile={profilename}
  4. anki://x-callback-url/getfields?noteid={notename}

It is not allowed to upload demo screen video, here are some screenshot



1 Like

Any suggestions for how AM should convey the data back to the app? It may be more than can fit in a URL. Maybe JSON on the clipboard?

hi dae:
Thanks your swift feedback.

Clipboard may be not such straightforward for user experience. Is it possible return a json string as x-success content if there is not so much info need carry

Here is x-callback-url usage by searching google(sorry, can’t include link here)
iOS
shortcuts
use-x-callback-url

To reduce disturbance of users, call x-callback-url only onetime and return a full set of profile data in single json string would be perfect, but if x-success can’t carry too much info, we at least can call 2 times to get note type, then get fields based on note type (usually user only have one default profile unless they specified). In this case we even do not need json. A comma separated note list or fields list string is enough.

Don’t know much about iOS development yet. Still learning. Anyway, thanks you implemented url schema when I suggested several years ago. At that time, I use it in iOS workflow(now it is shortcut). Now I think it’s time to develop an app to improve experience.

What do you mean? The calling app can send a message to AnkiMobile, which puts the data in the clipboard and then returns to the calling app. If it wants to keep the user’s clipboard, it can save it before calling AnkiMobile, and then restore it afterwards. That will allow us to pass a potentially large JSON message without worrying about having to divide it up into multiple back-and-forth calls.

AM will probably also need to get the user to confirm, since it’s a potential privacy violation otherwise.

sorry, maybe I did not make it clearer at very begining. I mean I want to use “x-success” feature of iOS x-callback-url to make 2 way communication.
say, my app named ‘ankiclip’. when I call ankimobile to get profile json string. I call it as

ankimobile://x-callback-url/getprofile?x-success=ankiclip://callback/result?

here I put x-success=ankiclip://callback/result? as one of your x-callback-url parameter. your app read the value of x-success, and attach json={your json string here} after it and call browser. so the url you called looks like ankiclip://callback/result?json={you json string here} . It will jump back to my app, so I can get the json string.

Some references for your information.

  • "Use x-callback-url " standard Apple doc.
    https://support.apple.com/en-hk/guide/shortcuts/apdcd7f20a6f/ios

  • x-callback-url spec:
    http://x-callback-url.com/specifications/

  • type-safe API to the x-callback-url scheme (Swift)
    https://github.com/ValentinWalter/Middleman

  • Sample from App Draft to get note content by UUID.
    https://docs.getdrafts.com/docs/automation/urlschemes#get

  • Sample from App Bear to return an array of notes (in json string) by specifying tag
    https://bear.app/faq/X-callback-url%20Scheme%20documentation/

1 Like

I am proposing something similar, but instead of passing the data as a URL parameter in the success URL, it would place it on the clipboard then call the URL, which would avoid issues with payload length.

Well, just thought copy data to clipboard maybe not safe, because other App may have chance to read that.

Anyway, thanks so much of your feedback. And hope this function can be fulfilled when you are convenient. :+1:

I’ve added it to the todo list, but it may take a while.

1 Like

Hi,
I am working on unified system for Anki deck generation.
For AnkiDroid, I will use the AnkiDroid API.
I have implemented it in
GitHub - krmanik/Anki-Occlusion: Image Occlusion for AnkiDroid

For Anki Desktop there are many possibilities but to use same HTML/CSS/JS across Anki Ecosystem, I have implemented this Chrome Extension to communicate with Anki using AnkiConnect addon from webpages.
GitHub - krmanik/anki-integration: Chrome extension to call AnkiConnect's supported actions from web pages

But for iOS, the only option is URL schemes, it works better for cloze generation or simple notes. It is not powerful as AnkiDesktop and AnkiDroid options.
AnkiMobile-Addons/ocloze at main · krmanik/AnkiMobile-Addons · GitHub

On iOS, every time it prompts for Open in Anki? and also it opens AnkiMobile. When cards added successfully it returns back. Also multiple notes are not possible to add. Images can be added but only from network not from local generated image. I have read about the URL schemes have those limitations and nothing can be done to reduce the friction.
I came to know about universal scheme but it only works for website owned by developer.

I have used genanki-js for generating decks inside browser and exporting .apkg file, which seems better.
But is any better way to create notes on iOS and adding notes directly to AnkiMobile?

May be it will be features request.

  • Option to add multiple notes
  • Option to add image/file from base64 with file name and type
  • Option to add model and card template if not exist
1 Like

apkg files were never intended to be used by other programs. In the future it may make sense to create another format for import/export that is designed to be easy for other programs to use.

1 Like

@ninja33 Please give the latest beta a try and let me know how the feature works out for you.

You’ll need to use anki://x-callback-url/infoForAdding?x-success=..., then extract the details with

let PASTEBOARD_TYPE = "net.ankimobile.json"
if let data = UIPasteboard.general.data(forPasteboardType: PASTEBOARD_TYPE) {
   // clear clipboard
   UIPasteboard.general.setData(Data(), forPasteboardType: PASTEBOARD_TYPE)
   // ... handle json
}
1 Like

thanks, will try and provide feedback