Skip to main content
March 4, 2022
Question

How do I create/attach a File Field to an existing item using the 1Password CLI

  • March 4, 2022
  • 9 replies
  • 1285 views

Trying to automate a workflow and was wondering how to use the 1Password CLI to attach/upload a File Field to an existing item. See uploaded picture with the file depicted. Any help would be much appreciated.

I noticed there is a separate item create and a document create. Is there someway to create a document in an item.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Referrer: forum-search:https://1password.community/search?Search=How%20do%20I%20create%2Fattach%20a%20File%20Field%20to%20an%20existing%20item%20using%20the%201Password%20CLI

9 replies

March 15, 2022

Hey @dild

We do not yet support attaching file field types to items yet in the CLI (with the exception of document type items) - but it is being tracked in our internal issue board.

August 31, 2022

Hey @"Justin.Yoon_1P"

Two questions regarding the file upload feature for 1Password CLI.

1) The docs at https://developer.1password.com/docs/cli/reference/management-commands/item/ provide some information that it should be possible with [file]=/path/to/your/file and I can't find any limitation regarding the document type items. Is it no supported? If yes, could yo provide an example?

2) Do you have an example for uploading files with 1Password CLI to document type items? Can not get it working, also no docs found.

Thanks for your help,
Oliver

1Password Employee
August 31, 2022

Hi @oliverroos, you're correct that it is not supported to attach file fields to document type items via the CLI at this time.

Document type items are currently only supported in the separate op document create command and adding file fields is only supported in op item create.

I'll file a feature request to add support for attaching file fields to Document type items via the CLI as well. Probably easiest to merge op document create and op item create (and similarly for edit).

In the meantime, here's an example how you can attach file fields to any other type of item:

echo "Hello from Simon" > hello.txt && op item create --title "Greeting" --category SecureNote "greeting[file]=hello.txt" && rm hello.txt

September 1, 2022

Hi @1P_Simon
many thanks for your reply and for file a feature request.
I tried your example, but this will end in the same error as many others i tried before:


echo "Hello from Simon" > hello.txt && op item create --title "Greeting" --vault="demo" --category SecureNote "greeting[file]=hello.txt" && rm hello.txt

will result in a error:

[ERROR] 2022/09/01 12:46:46 Failed to create item: assignment statement number 1 is not formatted correctly - "file" is not a supported field type. Use: [<section>.]<field>[[fieldType]]=<value>

I'm on 1Password version 8.8 if that helps :)

1Password Employee
September 2, 2022

Hi @oliverroos, what is the output of op --version? It needs to be https://app-updates.agilebits.com/product_history/CLI2#v2050001 or later.

You can find https://developer.1password.com/docs/cli/reference/update

September 2, 2022

Sorry @1P_Simon , did just copy the example for cli download instead of checking the version in the example first ...
https://developer.1password.com/docs/cli/get-started/

Obviously, you're right. With the newest cli installed it works like expected :)

1Password Employee
September 5, 2022

Awesome, glad to hear it's working for you now, Oliver!

November 3, 2022

For those searching, it is possible to create a document with the op document create command, and then edit it with op item edit to add any fields you require 👍

1Password Employee
November 15, 2022

Thanks for your feedback!