First steps with the CLI

joaov777joaov777
edited July 2018 in CLI Beta

Hello there, everyone.

I have been taking my first steps with the 1Password CLI and it's been nice. I have also taken a look and followed the examples provided on the get started page for the CLI. However, as expected, some doubts have raised and although they are simple, I guess this could help some other users that might start using the CLI.

It all got mixed up when I tried to actually create items. I didn't understand the relationship between the commands "create item", "encode item", "get template", etc. I guess as examples are provided, it will make it easier to understand the logic.

Some of my needs are:

  1. How to create a new entry? (login, secure note, etc)
  2. How to update such entry?
  3. How to know which fields I have available for each category? (Login, Secure note, etc.)
  4. If possible, how to retrieve a password from an specific item located in a vault? By that I mean, I apply the command and only the password of an item is returned instead of a long and comprehensive message that I seemed to get all the time.

I believe more doubts will appear down the road. Thanks in advance!


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • cohixcohix

    Team Member

    Hey @joaov777 ! Let me try to shed some light on the questions you have.

    First off, the relationship between create item, encode, and get template:

    op get template is the command you run when you want to get a completely empty item of a particular type. So if I run op get template login, the output is JSON that represents that item type. You can save that JSON to a file to edit it, or you can use the jq tool to manipulate it on the command line.

    Once you have filled out your item JSON with the values you want, now comes op encode. If you take the filled-out item JSON and pipe it into that command, you get the input needed for op create item. For example:

    op create item login $(op get template login | op encode) --title="Empty Item" --tags=empty,great,cool

    Gives you an empty login item with the title and tags you passed.

    If you do something like op get template login | jq . > item.json, that will create a file that is easily editable in any text editor to insert the values you desire. You can then do op create item login $(cat item.json | op encode) to create an item from that template. Sound good so far?

    Great. As for updating, the CLI does not support item editing as of yet, but it's something we're working on supporting. We're not at all happy with the complexities of item handling in the CLI, so we're working on making the whole experience better.

    You know which fields are available in an item type by getting its template and looking at the JSON :) Some of the fields can be confusing, so don't hesitate to ask me here, or you can also try creating an item with one of our other apps, doing op get item on it, and inspecting the JSON to see what everything is.

    If you want to get just the password from a login item, you'll need to use jq: op get item [name] | jq '.details.fields[] | select(.designation=="password").value' -r

    This filters the item JSON down in three parts: first, get the fields, then select the field where designation=password, then print its value. The -r flag prints the raw value rather than a quoted string.

    I hope this helps, please let me know if you have any questions.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file