Skip to main content
August 24, 2021
Question

anyone have examples of editing existing Vault entries from CLI?

  • August 24, 2021
  • 11 replies
  • 668 views

I have several vaults within our company's division where we would like to add more entries for all.
I am looking for a path that I can follow to automate this.
I understand the limitation, but are there any proven solutions?

I was expecting to be able to op get item(s) and pull the data in json format, modify this data to include the new entries that I wanted to add, and then import this in as a new item.

What would be the correct commands to accomplish this?


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

11 replies

September 2, 2021

Hello @adrianbj,

It sounds like you are trying to add in these new fields into one of the sections and that you're running into difficulty when a Login item has multiple sections.

You have a few different options to be able to add these new fields programmatically using jq.

  1. Add the new fields into the first section of the Login item,
  2. Add the new fields into the last section of the Login item,
  3. Create a new section that only contains your new fields.

Personally, I feel like Option 3 is the best aesthetically for the user, so I'll show you how to use jq to achieve that first.

Option 3: Create a new section that only contains your new fields

The += operator in jq allows you to merge one array into another array, like so:


jq '.sections += [{"title": "Section added by administrator", "fields": [{"k": "string", "t": "Purpose of the credential", "v": "enter text"}]}]' details.json

You'll note that the second half of the += operator is an array that contains an entire section object.

And here's a screenshot of how that will appear in 1Password.

We've created a brand new section called Section added by administrator that contains the one field we added in the array.

Option 2: Add the new fields into the last section of the Login item

If your goal is to combine these fields into an already-existing section, then here are those steps.

Similar to above, we are using the += operator to merge two arrays together. The source array is going to be the final section’s fields. In this case, we are merging in an array of field objects, rather than an array that contains a section object. Note that negative indices are allowed, with -1 referring to the last element, -2 referring to the next to last element, and so on.


jq '.sections[-1].fields += [{"k": "string", "t": "Purpose of the credential", "v": "enter text"}]'

And here's what that looks like:

You can see that our new Purpose of the credential field has been added into the Already existing section section.

I hope that this helps. Please feel free to write back with any additional questions you may have.