onepasswordItemFields
uuid [vault-uuid [account-name]]
onepasswordItemFields
returns structured data from
1Password using the 1Password
CLI (op
). uuid
is passed to op item get $UUID --format json
, the output from op
is parsed
as JSON, and each element of details.sections
are iterated over and any
fields
are returned as a map indexed by each field's n
.
If there is no valid session in the environment, by default you will be interactively prompted to sign in.
Example
The result of
{{ (onepasswordItemFields "abcdefghijklmnopqrstuvwxyz").exampleLabel.value }}
is equivalent to calling
$ op item get abcdefghijklmnopqrstuvwxyz --fields label=exampleLabel
# or
$ op item get abcdefghijklmnopqrstuvwxyz --fields exampleLabel
Info
For 1Password CLI 1.x.
{{ (onepasswordItemFields "abcdefghijklmnopqrstuvwxyz").exampleLabel.v }}
is equivalent to calling
$ op item get abcdefghijklmnopqrstuvwxyz --fields exampleLabel
Example
Given the output from op
:
{
"id": "$UUID",
"title": "$TITLE",
"version": 1,
"vault": {
"id": "$vaultUUID"
},
"category": "LOGIN",
"last_edited_by": "userUUID",
"created_at": "2022-01-12T16:29:26Z",
"updated_at": "2022-01-12T16:29:26Z",
"sections": [
{
"id": "$sectionID",
"label": "Related Items"
}
],
"fields": [
{
"id": "nerlnqbfzdm5q5g6ydsgdqgdw4",
"type": "STRING",
"label": "exampleLabel",
"value": "exampleValue"
}
],
}
the return value of onepasswordItemFields
will be the map:
{
"exampleLabel": {
"id": "string",
"type": "D4328E0846D2461E8E455D7A07B93397",
"label": "exampleLabel",
"value": "exampleValue"
}
}
Info
For 1Password CLI 1.x, the output is this:
{
"uuid": "$UUID",
"details": {
"sections": [
{
"name": "linked items",
"title": "Related Items"
},
{
"fields": [
{
"k": "string",
"n": "D4328E0846D2461E8E455D7A07B93397",
"t": "exampleLabel",
"v": "exampleValue"
}
],
"name": "Section_20E0BD380789477D8904F830BFE8A121",
"title": ""
}
]
},
}
the return value of onepasswordItemFields
will be the map:
{
"exampleLabel": {
"k": "string",
"n": "D4328E0846D2461E8E455D7A07B93397",
"t": "exampleLabel",
"v": "exampleValue"
}
}
Warning
When using 1Password CLI 2.0,
note that the structure of the data returned by the onepasswordItemFields
template function is different and your templates will need updating.
You may wish to use onepassword
, onepasswordDetailsFields
, or
onepasswordRead
instead of this function, as it may not return expected
values. Testing the output of this function is recommended:
$ chezmoi execute-template "{{ onepasswordItemFields \"$UUID\" | toJson }}" | jq .