Forum Discussion

Former Member's avatar
Former Member
4 years ago

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

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

  • Former Member's avatar
    Former 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 👍

  • 1P_Simon's avatar
    1P_Simon
    Icon for 1Password Team rank1Password Team

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

  • 1P_Simon's avatar
    1P_Simon
    Icon for 1Password Team rank1Password Team

    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

  • oliverroos's avatar
    oliverroos
    Occasional Contributor

    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 :)

  • 1P_Simon's avatar
    1P_Simon
    Icon for 1Password Team rank1Password Team

    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's avatar
    oliverroos
    Occasional Contributor

    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

  • Former Member's avatar
    Former Member

    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.