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
Team Member
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:There are two custom fields in this example JSON:
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
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.
Team Member
I have forwarded this feedback to our team @Isaac , thank you