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

dild
dild
Community Member

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:How do I create/attach a File Field to an existing item using the 1Password CLI

Comments

  • 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.

  • oliverroos
    oliverroos
    Community Member

    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

  • simon_1P
    edited August 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
    
  • oliverroos
    oliverroos
    Community Member

    Hi @simon_1P
    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 :)

  • Hi @oliverroos, what is the output of op --version? It needs to be 2.5.0 or later.

    You can find update instructions in the 1Password CLI docs

  • oliverroos
    oliverroos
    Community Member

    Sorry @simon_1P , 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 :)

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

  • bbeckford
    bbeckford
    Community Member

    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 👍

  • Thanks for your feedback!

This discussion has been closed.