It’s Cybersecurity Awareness Month! Join our interactive training session, or learn about security and AI from 1Password experts.
Forum Discussion
adrianbj
5 years agoNew Contributor
anyone have examples of editing existing Vault entries from CLI?
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 a...
Former Member
5 years agoHello adrianbj,
Thanks for writing in! My name is Michael, and I'm one of the developers on the team responsible for the command-line tool.
As @"keith.craig" mentioned, there are currently some limitations in how editing of an item works using the command-line tool. We are definitely aware of these limitations and are looking to address them in an upcoming release. The state of the "edit item" command is nowhere near where we want it to be.
In the meantime, the workaround that you mentioned on August 24th should be suitable for your use case. You'll need to:
- Use
op get itemand save that as a JSON file. - Make the edits needed in that JSON file.
- Use
op create itemand upload that JSON file. Note that thecreate itemcommand expects the title and the URL field to be passed as flags, instead of in the JSON. - Verify that the newly-created item looks as you’d expect.
- Delete the original item.
- Clean up the temporary, unencrypted JSON files.
We highly recommend using the utility https://stedolan.github.io/jq/ to help manipulate your JSON content in these steps.
Here are sample commands (that you might need to tweak for your use-case):
```bash
0. Set up your vault name and item name here:
export VAULT_NAME='your-vault-of-choice'
export ITEM_NAME='the-item-to-duplicate'
1. Get the item and fields-as-flags, storing each in their own file.
op get item --cache --vault "$VAULT_NAME" "$ITEM_NAME" > item.json
jq '.details' item.json > details.json
jq -r '.overview.title' item.json > title.txt
jq -r '.overview.url' item.json > url.txt
jq -r '.uuid' item.json > uuid.txt
2. Make the edits you need
3. Upload the edited item
I am assuming that these are Login items, based on your sample data,
but you can specify the category as needed.
Unfortunately, create item only supports setting one URL.
op create item Login \
--vault "$VAULT_NAME" \
--title "$(< title.txt)" \
--url "$(< url.txt)" \
"$(op encode < details.json)"
4. Verify that the newly-created item looks as you'd expect.
5. Delete the original item
In case you did not modify the title, we refer to the original’s UUID.
op delete item --vault "$VAULT_NAME" "$(< uuid.txt)"
6. Clean up the temporary storage files
rm item.json details.json title.txt url.txt uuid.txt
```
You might need to adapt some of these commands for your specific use case, but I hope that this is a useful jumping off point.
Since you also asked about 1pif files, I should mention that the command-line tool does not work with 1pif files.
I hope that these workarounds are enough to help you proceed with making the changes you want within your division’s vaults. Again, we know that this is less than ideal, so keep an eye out for a future release where we improve this workflow.
Please feel free to write back with any additional questions you may have.