-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add api endpoint to add citations to an item by libraryID and itemID #148
base: master
Are you sure you want to change the base?
Add api endpoint to add citations to an item by libraryID and itemID #148
Conversation
Unfortunately, I am having CORS issues: trying to access the connector endpoint from a python script running in a virtual machine (Windows WSL2) fails because the connector server only seems to accept connections from localhost. Similarly, I cannot connect to the connector server from a script running in another window served from a different port. I fear that's probably nothing that can be changed, since the Zotero people will probably not add a more liberal CORS header. |
Web browsers cannot connect, but a python script should be fine, I do it all the time. |
My python cgi script tries to connect from 127.0.1.1 (WSL2 Ubuntu VM) to the Zotero server listening on 127.0.0.1 and it refuses the connection. Maybe it is a firewall issue, though. I'll switch to a Mac where it should work. |
Try setting another agent header |
Ok, I got it working but soon discovered that the existing connector API does not provide the methods I need for programmatically adding the reference data that I want to link with cita (or I didn't find them in docs or in the source), such as methods to lookup items in order to avoid duplicates, or to create them if they don't exist already. Would you consider adding the endpoints that I put here to your PR? I tested them by pasting the code into the "Run JavaScript" console, which works well. Although they do what they should, they are not 100% ready yet because I want to test them in my workflow first (maybe I need another method or additional data). But maybe you can already have a look now. |
@Dominic-DallOsto One comment regarding parameter names: Maybe it would be better to rename |
@Dominic-DallOsto I have added more connector endpoints: https://github.com/cboulanger/excite-docker/blob/main/zotero/zoteroOverlay.jsx - maybe it makes sense that I create a PR to add them after your PR has been merged. They add capabilities that are essential to work programmatically with the cita plugin from outside Zotero. |
That makes sense!
Thanks, that looks great! Actually I was thinking maybe this would make more sense as a separate extension, because most of the functionality is for working with Zotero data generally and it might be something others who don't necessarily use Cita would be interested in? Then I think anything specific to citations should be part of Cita. What do you think? Would you like to do up an extension? Otherwise I can quickly do it tomorrow. |
You are right that these features go beyond Cita and should really be part of a more general set of query features for the connector (and there are lots more that I would wish to be available). I found the prerequisites of plugin development a bit involved and have shied away from it so far, so if you would set up the infrastructure for a separate plugin, that would be really great and I would be happy to contribute to it! |
If you don't mind typescript, I have a yeoman generator for zotero plugins which scaffolds a plugin plus the infrastructure to do releases. |
Thanks! I'll whip this up quickly. |
That sounds wonderful! I really like TypeScript because it catches so many bugs in advance and is self-documenting. |
Thank you. We can then open up issues discussing which endpoints should be available and what data they should return. |
I just posted this issue retorquere/generator-zotero-plugin#20 I'm having with running the plugin |
@cboulanger There's an initial version up here. Hopefully I didn't break anything. And it should be possible to tidy up a lot of the checks with Typescript. |
@Dominic-DallOsto Really great job - so fast and beautiful code, too! Looking forward to trying it out and I'll certainly contribute some more endpoints. It is great to have a place to add them. I have always been missing a fast and reliable way of scripting Zotero in a cross-platform way. The zotero.org web API is great and everything, but this is much more versatile (and extensible, too). |
585af77
to
19d96ae
Compare
Updated now with new methods - see what you think / if it works for your workflow |
Ok, I think this is finished and ready for review now. The only additional change is that when adding a citation to a Zotero item, that Zotero item will be automatically linked in the citation. |
Hi all! Thanks for the work you've put into this. I wasn't aware of the extensibility of the Zotero HTTP server, and I like to see that Cita can be integrated into automated workflows through it. And I really like the brand new zotero-api-endpoint plugin. Congratulations! I have reviewed the changes in the pull request and I generally like them. I do have some comments, though: First, I like that you've put the initialization code in the Then, I think that the specifics of the Regarding the To solve this, I would suggest that we change the SourceItemWrapper class'
This would also work for links that may have been established by manually editing (discouraged) the Citations note attachment (instead of using the GUI). I'll post a separate issue for this too: #157. On the other hand, regarding the Regarding the endpoints, I think we should:
Finally, do you think we may provide basic API documentation in a root I think that pretty much covers everything I thought while reviewing this PR. In short:
I'll try to reply to future comments and changes as soon as possible! Thank you again!! |
@diegodlh Thank you for your thoughful review, I think it is a very good idea to integrate the target feature better into the existing cita infrastructure. As to your suggestion to align the requests better with the HTTP methods, that is certainly better practice than putting everything into the POST data. However, in terms of API documention/service discovery I think separating request data into a GET querystring and POST data makes validation and documentation more complicated. In zotero-api-endpoint we use some wizardry to convert the typescript information into json-schema files which can then be used to validate the input and could further be transformed into OpenApi/Swagger information with little cost. I wonder if that's something that could be interesting for Cita, although it might be an overkill for three service methods. |
Thinking about it some more, the question for me is if the effort of making the API RESTful, given a server that doesn't let you parse out dynamic URI components (such as |
Regarding this, I also liked the idea of using
Yes, regarding documentation I agree that doing something very complicated would not be urgent right now. I would at least provide some docs in the Readme or in a landing page at the root
I'm quoting part of your email yesterday, concerning the zotero-api-endpoint plugin, I believe. I think it applies here too. I think I prefer an initial API that looks more like how we want it to be in the long term. However, if making some of the changes I suggested would delay merging this PR too long, I guess we may open a separate issue and address these in the future. |
It does in fact not add the
|
Thanks for the super detailed review - I'll go through step by step:
That makes a lot of sense, yep!
Yep - will follow up in #157. A solution that works when passing in Zotero keys to the constructor would be most idiomatic if possible I think.
That makes sense as well!
I'm not sure if it's possible to mix query string parameters and post data. I'll investigate this more here (Dominic-DallOsto/zotero-api-endpoint#14) - but initially reading the docs, it looks like we can only get either the query string (if it's a GET request) or the post data (if it's a POST request) but not both. I'm not sure if DELETE requests are supported - I will have to check.
That sounds good. Would relate to #4 #125.
Definitely docs would be a good idea. We'll think about what this should look like. |
Given the limitations of the Zotero server, I would suggest that we stick to GET/POST as it is now and improve in the case that the Zotero devs improve the server to process requests in a more RESTful way. |
@cboulanger, this should be addressed with #157.
I think I was partly wrong here:
Apparently it is. See my last comment in Dominic-DallOsto/zotero-api-endpoint/issues/14
Just checked: they are not supported. |
Fixes #144
Adds the endpoint
/cita/citation/add
by which citations (listed by itemKey) can be added to an item (identified by libraryID and itemKey)An example request in python:
addCitationsByKey
anddeleteCitationsByIndex
toSourceItemWrapper
SourceItemWrapper.deleteCitations
with explicitsync=false