Skip to main content
stopsineman
August 18, 2022
Question

How can I retrieve the file referenced by a 'Document' Item via the V2 CLI?

  • August 18, 2022
  • 3 replies
  • 2944 views

I have several 'document' Items stored in a Vault that I'd like to reference dynamically from the command line rather than having to download them from the 1Password App and reference them on my filesystem. Is there a way to do that? I can see the file in the output of


op item get --vault '<vault>' '<item nam>' --format json | jq '.files[0].content_tpath'

but I can't actually get the file itself in anyway that I can tell.


$ op --version
2.2.0


1Password Version: 8.8.0
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided

3 replies

August 20, 2022

Hey @stopsineman,

Starting with 1Password CLI 2.5.0, files within document-type items can also be referenced by the means of secret references.
Have a look at https://developer.1password.com/docs/cli/secrets-reference-syntax for more details.
So a string such as op://<vault-name>/<item-name>/<file-name> would be a reference to the underlying document, which can be resolved using, for instance, op read:

op read op://<vault-name>/<item-name>/<file-name>
<your-file-content>

You can find more information about our secret provisioning commands here: https://developer.1password.com/docs/cli/secret-references

Let us know if this helps!
Best,
Horia

stopsineman
August 20, 2022

Neat! I'll give this a try on Monday after I figure out why I'm stuck on 2.2.0… :)

1Password Employee
September 2, 2022

Thanks! Glad we could help. Let us know how this works out!