Get userID from username

I'm writing some code that pulls items from a user's library. In time, it may grow authentication to work with private libraries, but for now, I'll settle for working with public libraries.

For a user visiting with a browser, my library is accessible just using my username:

https://www.zotero.org/takowl/items

However, for the API, I need to use my numeric userID, found in my settings. For now, I'm asking users to copy this in manually from their settings, but this is not a very nice experience. Is there a programmatic way to get a userID from a username, without dealing with oauth?
  • This should do it, if a solution based on the local Zotero client is sufficient:
    Zotero.userID
  • Thanks, but as I understand it, that would need to be running in the same context as the Zotero client? My code is JS running in the general web browser context, and there doesn't appear to be a Zotero object, even with Zotero for Firefox installed.
  • The userID is, of course, on the item page (in various load-dataconfig elements), so you could grab it from there, but I take it that's not what you have in mind?

    If you want an API way to send a username and get the userID without OAuth, I don't believe that exists.
  • Yep, without the user ID, I can't get an item, so that doesn't help. Thanks for the information; I'll put OAuth somewhere on my to-do list.
  • no, I mean - it's listed all over the place on the library view page, you don't need to go to a specific item.

    Just go to
    https://www.zotero.org/<username>/items
    and you'd be able to scrape the userID from the page.
  • Ah, I see. Thank-you.
  • That function should really be part of the API though.
  • takowl: You should post this to zotero-dev for further/future discussion.
Sign In or Register to comment.