Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
Former Member
3 years agoRecommended way to use credentials in the code - NodeJS
Hi!
I have a NodeJS application and I'm trying to figure out the best way to use 1Password Secret Automation. I already have a Connect server in place and also already did some tests successfully....
Former Member
3 years agoHey @imftec,
Our Connect JS SDK does support getting the item's details when you look for it by title. This is achieved with the function you mentioned: getItemByTitle
.
In order to work, it is expected that the item's title to be unique, otherwise the client will throw an error (saying that there are too many items with the same title).
Here's a snippet of a sample js
file that will print a list of an item's fields (in JS fields are stored in objects named FullItemAllOfFields
). You should be able to see all the details of all the fields the item contains. The snipper is using the latest version of the SDK, which is 1.3.0
.
```js
import { OnePasswordConnect } from "@1password/connect";
// Create new connector with HTTP Pooling
const op = OnePasswordConnect({
serverURL: process.env.OP_CONNECT_HOST,
token: process.env.OP_CONNECT_TOKEN,
keepAlive: true,
});
const vault = await op.getVaultByTitle("Your Vault Title")
const item = await op.getItemByTitle(vault.id, "Your Example Item");
console.log(item.fields)
```
To get an item's field's value (based on its label). you can use a line like the following:
js
item.fields.find(o => o.label === "your-field-label").value
Does this help in realising your use case? Is there something else you're running into when trying to get your desired secrets with our Connect JS SDK?
Let us know.