Javascript API to search not working, what am I missing?

I use following code to try to search the library:


let s = new this.Zotero.Search();
s.libraryID = this.Zotero.Libraries.userLibraryID;
s.addCondition('joinMode', 'any');
s.addCondition('DOI', 'is', 'example-DOI');
let results = await s.search();
let items = await this.Zotero.Items.getAsync(results);

The Javascript API page (https://www.zotero.org/support/dev/client_coding/javascript_api) tells me to use 'await', like in the example above. However I get a JS SyntaxError: await is only valid in async functions and async generators.

If I look at the source code (https://github.com/zotero/zotero/blob/master/chrome/content/zotero/xpcom/data/search.js)

I get the following SyntaxError: yield is a reserved identifier.

What am I missing?
  • I just found the answer myself. The calling function had not been defined as async.
  • If you have further API questions, please post them to the Zotero-dev Google group. You’ll get faster responses there and we try to keep overly technical discussion off these forums.
Sign In or Register to comment.