Creating link attachments using the javascript API

edited 5 days ago
I am trying to create a link attachment to a locally stored PDF file using the javacript API (I later want to automate this and run this in a loop). However, the following code is not working (I am on Zotero 7.0.11, on Linux).

```
//parentID is an integer set to the ID of the parent. I have checked the correctness of the parentID parameter using SQL, and by creating a note using the Javascript API (which works exactly as intended

var at = new Zotero.Item("attachment");
at.linkMode = 2; // For link attachments/
at.parentItemID = parentID;
at.path="/home/piyushs/file.pdf";
id = await at.saveTx();
Zotero.log(id);
```

What happens is that an attachment item is created, but it is not attached to the parent item, and it also does not contain the filepath information.

Where should I look in the js code to see what fields/functions to use?

Thank you.
Sign In or Register to comment.