Provisionning pdf from shell

Hello,

Is there any command to send a pdf (or any other type of) file into my opened zotero library with a shell command ?

I work under linux and for certain activities, I would need to script my zotero provisioning.

Anyone to help ?

Thanks,

Olivier
  • If you use syncing, you could do it easily using the Zotero API (with the pyzotero library, for example). Zotero will pull down changes immediately, so you'd have it in Zotero within a few seconds. The one downside is that you'd then need to right-click on the file and choose Retrieve Metadata for PDF — that won't happen automatically for files added via the API.

    We're planning to make it possible to "open" local PDFs via Zotero and then run metadata retrieval on them, though that would result in a prompt in the UI (similar to when you open a RIS file via Zotero).

    There are ways to script this entirely locally, but they'd be a bit more complicated, so see if the API approach works first.
  • Hello,

    thank you Dan for your response. As I understand it, pyzotero methods like "Zotero.attachment_..." could help me then.

    However, I'd prefer to talk directly with a local zotero opened instance really. What I would need is simply to send pdf files into my zotero library from a shell (or a shell script). I suspect that it's possible to send some commands to do that to the localhost through port 23119 ?

    Olivier
  • Ah ! I think I may have found what I was looking for :

    https://forums.zotero.org/discussion/75569/client-scripting-api-with-zotero-standalone-v5

    Let's go for investigations :-)
  • Hi Dan,

    I've been able to push a web page into my library from a shell using the three following three commands :

    #get the web page to store

    $ curl -fsSo /tmp/doc http://url-to-store

    # generate the json db file to be used by zotero

    $ jq -cn --arg uri http://url-to-store --rawfile html /tmp/tmpdoc '{url: $uri, html: $html, cookie: ""}' > /tmp/tmpjson

    # push to zotero with method "saveSnapshot"

    $ curl -vfH Expect: -H 'Content-Type: application/json' --data-binary "@/tmp/tmpjson" "http://localhost:23119/connector/saveSnapshot"

    Unfortunatly, I have not been able to push a pdf file since I have not found which method/json format should be used to push a binary file such as pdf.

    Could you help ?

    Thanks,

    ---
    Olivier

  • I have not been able to push a pdf file since I have not found which method/json format should be used to push a binary file such as pdf.
    You can't — PDFs are downloaded by Zotero. You can use the browser devtools to inspect the requests made by the Zotero Connector when you save a PDF for reference.
  • Today I've once again been annoyed that this (adding pdf via cli) is not possible and thus wrote a small script to do this:

    https://github.com/sdx23/zotadd

    Feedback welcome.
  • The downside to that is that you'll end up with an imported-URL attachment that shows a permanently broken localhost URL rather than a stored-file attachment that doesn't display a URL.
  • Can this be avoided? And if so, how?
  • edited March 31, 2020
    Only by using the JS API or the web API. The endpoint you're using is for the connector, which only saves PDFs with URLs.
  • Thanks. The most viable way seems then to update/fix the upload methods in pyzotero or use some different bindings to the web API.

    Myself, I extremely rarely use the URL of an attachment, so I'm just gonna life with it.
  • Hello, zotadd is a really useful script to push file to my local zotero.

    I was wondering how should I specify a specific library/collection into which all documents pushed with zotadd would be stored.

    For example, I plan to push certain incoming mails automatically to a specific library called "mails" into a specific collection called "incoming".

    I have tried to include in the json part of "zotadd" a parameter "collection", but it doesn't work. Any help ?

Sign In or Register to comment.