Creating a new field using op command line tool
Hi - What's the correct syntax to create a field inside an object and set a password for it? We're trying to look to see if a field exists, grab it's contents and if it doesn't then create the field and set a password then grab it again.
./op edit item UUIDadsfasdfUUID softwareupdate= --generate-password
[ERROR] 2021/02/11 14:27:31 The item doesn't have a "softwareupdate" field.
1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided
Comments
-
Hey @Isaac ,
The
op edit item
command currently does not allow creating new fields, it only allows editing existing fields. We hope to improve this in the future though!In the meantime, you can create a new item with all the relevant fields using the
op create item
command: https://support.1password.com/command-line-reference/#create-itemTo create an item with custom fields, you have to create a json item, encode it, and pass it into the
op create
command. The json item can look like this:{ "sections": [ { "fields": [ { "k": "string", "n": "softwareupdate", "t": "Software Update", "v": "PlainTextValue" }, { "k": "concealed", "n": "softwareupdate2", "t": "Software Update 2", "v": "StrongPassword123" } ], "name": "section_name", "title": "Section Name" } ] }
There are two custom fields in this example JSON:
- The first field is a plain text field called "Software Update" and the value in it would read "plainTextValue" in plain text (e.g. for values that are not secrets such as names and descriptions).
- The 2nd field is a password field (concealed) and is called "Software Update 2". The value in it is "StrongPassword123" which will be concealed as a password field.
- The "name" and "title" part is for creating that entire section in the custom item. Creating sections and giving them titles will make things easier when organizing (and editing) logins.
Now, let's say you saved that JSON and called it
softwareupdate.json
, then your command to create that item should look like this:op create item Login --title NewItemTitle --vault NameOfVault $(op encode item < Path_To_softwareupdate.json)
As for generating a password, the
--generate-password
variable can only be used for the main password field of any give item, and cannot generate a password into a custom field, so if you use the--generate-password
variable you will overwrite the item's main password field with a new one.I hope this will point you in the right direction :)
0 -
Gotcha, thanks. It'd be nice to add secondary password fields to an existing item and randomly generate their data via the command line. Sometimes there are secondary accounts to a service we would want to document, like a read only API user, that doesn't warrant its own item entry.
0 -
will new fields be added to existing records if you add them to the template from which those records were created?
0 -
Hey @adrianbj ,
The CLI tool was made to provide users with the tools to build their own scripts and workflows to automated processes. You can write a script that exports all 700 items to a JSON, then edit the JSON of each entry and add whichever field you'd like, then import it all back into 1Password.
@itsthecode No. If you use the
op create item
command it will create a new item, even if it is from a template that was already used.0