"Use 1Password CLI to Create Items | 1Password Developer Documentation"

`` Learn how to use 1Password CLI to create and retrieve items.

Requirements​

Before you can use 1Password CLI to create items, you'll need to sign up for 1Password and install 1Password CLI. To follow along with this tutorial, create a new vault named Entertainment where the example items will be saved:

op vault create Entertainment  
## Create an item​
You can use op item create to create a new item, and specify the item's details with flags.
To create a Login item called Netflix in the Entertainment vault:
  - bash, sh, zsh
  - Powershell
op item create \  
    --category login \  
    --title "Netflix" \  
    --vault Entertainment \  
    --url 'https://www.netflix.com/login' \  
    --generate-password='letters,digits,symbols,32' \  
    --tags netflix,login,family,share  
Here's what each of the above flags does:
  - --category Sets the item type, in this case a Login item. Use op item template list to get a list of category names.  
The category value is case-insensitive and ignores whitespace characters. For example, the Social Security Number category can also be specified as socialsecuritynumber.
  - --title Gives the item a name so that you can easily identify it. If unspecified, 1Password CLI selects a default name. For example, Untitled <category>.
  - --vault Specifies which vault the item should be created in. If unspecified, the item will be created in your Private vault.
  - --url Specifies the URL associated with a Login item. When set, 1Password in your browser will suggest the Login item when you visit the webpage.
  - --generate-password Generates a strong password for Login and Password category items. You can specify a password recipe, as shown in the example.
If left unspecified, a default recipe will be used to generate a 32
character password consisting of letters, digits, and symbols.
  - --tags Adds tags to the item using a comma-separated list. The tags flag can also be used to narrow your search when retrieving items.
For example, the command op item list --tags=family,share will return all items
with the family or share tags.
## Specify additional fields​
In addition to the fields you can set with op item create flags, each item category has its own set of built-in fields that you can use to save additional information about an item. You can also create custom fields to add other details, like security questions, PINs, contact numbers, and more.
To find the built-in fields for a given item category, run this command to retrieve the item's template:
op item template get <category>  
Use op item template list to get a list of all item categories.
For a Login item, the built-in fields are username, password, and a field designated for additional notes.
You can use the template to confirm that the username and password fields are available to set. If the field you want to add isn't included in the template for the category of item you're creating, use a custom field instead.
You can create custom fields with any of the following field types:
  - password
  - text
  - email
  - url
  - date (format: YYYY-MM-DD)
  - monthYear (format: YYYYMM or YYYY/MM)
  - phone
**Login item template**
{  
  "title": "",  
  "vault": {  
    "id": ""  
  },  
  "category": "LOGIN",  
  "fields": [  
    {  
      "id": "username",      "type": "STRING",  
      "purpose": "USERNAME",  
      "label": "username",  
      "value": ""  
    },  
      "id": "password",      "type": "CONCEALED",  
      "purpose": "PASSWORD",  
      "label": "password",  
      "password*details": {  
        "strength": "TERRIBLE"  
      },  
      "id": "notesPlain",      "type": "STRING",  
      "purpose": "NOTES",  
      "label": "notesPlain",  
    }  
  ]  
}  
### Assign fields to an item​
You can assign built-in fields and custom fields to your item in two different ways:
  - Use field assignment statements as arguments
  - Use the --template flag to provide an item template filepath
#### Use field assignment statements​
The op item create command can take a list of assignment statements as arguments to assign fields.
Assignment statements are formatted like this:
[<section>.]<field>[[<fieldType>]]=<value>  
For built-in fields, fieldType is implied by the item template and does not need to be specified. For custom fields, fieldType is optional, and if unspecified will default to password.
Here's an example of how to specify custom fields for a date, email address, and phone number using assignment statements:
'Personal Info.My Birthday[date]=1988-09-19'  
'BankCard.PIN=3901'  
'workemail[text]=john.doe@acme.org'  
You can add both built-in and custom fields to the Netflix example from above:
    --title "John's Netflix" \  
    --tags netflix,login,family,share \  
    'username=john.doe@acme.org' \  
    'Subscription Renewal Date[date]=2022-12-31'  
#### Use item template files​
You can also assign built-in and custom fields by saving the item category template to a file, then editing it directly. To get the template for a Login item:
op item template get login > loginTemplate.json  
This will write a file that looks like the following:
      "id": "username",  
      "type": "STRING",  
      "id": "password",  
      "type": "CONCEALED",  
        "strength": ""  
      "id": "notesPlain",  
Set the built-in fields username and password by filling out the their values.
For custom sections, section JSON objects can be inserted into the sections array of the template.
For custom fields, field JSON objects can be inserted into the fields array of the template.
To add a custom field into a custom section, specify an ID for the custom section and add it into the custom field.
  "sections": [  
      "id": "my*section*1",  
      "label": "My Example Section 1"  
  ],  
      "id": "my*field*1",  
      "section": {  
        "id": "my*section*1"  
      "label": "My Example Field 1",  
      "value": "hello world!"  
A section's label is the displayed title of the section. The id
represents an internal unique key. If the item has multiple sections,
each of their IDs must be different from one another.
A field has four keys that should be filled out:
  1. type determines the type of a field, similar to the fieldType in the assignment examples. Supported types are:
        - concealed - for password fields
        - string - for text fields
        - date - accepts numeric values that represent epoch time
        - monthYear - accepts integer values in the YYYYMM format
        - email
        - phone
        - url
  2. id is an internal unique key for the field. A section may not have multiple fields with identical id values. If left empty, the CLI will generate an ID.
  3. label is the display title for the field.
  4. value is the field's value, and the value can be strings or numbers depending of the field's type.
After you fill out the template, you can save it and pass it into the op item create command by using the --template flag to specify its path. The item category will be specified by the template, rather than a flag. For example:
    --template 'login.json'  
## Retrieve an item​
In addition to creating items, you can also use 1Password CLI to retrieve items.
To return details about an item, use the command op item get. The output for op item get is formatted similarly to item category templates, so that you can use the information for an existing item to create a new item.
[Learn more about the options available for item get.](/docs/cli/reference/management-commands/item#item-get)
Here are some examples of different ways to retrieve items:
List commands with JSON output formats can be piped into get commands to filter items. This example retrieves all items that are logins and have the netflix or family tags:
op item list --categories login --tags netflix,family --format json | \  
op item get -  
You can specify an item by name and request specific fields. Specifying a vault will reduce the risk of running into API limits when retrieving items.
op item get "John's Netflix" --fields label=username,label=password --vault Entertainment  
You can also specify items and vaults by ID, instead of by name.
op item get ozgnrmui6hynliiuceow4r5vdm --fields label=username,label=password \  
  --vault bcrdvqoaqsgiwkpehhclwnaooq  
## Learn more​
  - [Item template JSON format](/docs/cli/item-template-json)
  - [Work with items](/docs/cli/reference/management-commands/item)
  - [Work with vaults](/docs/cli/reference/management-commands/vault)

-"Use 1Password CLI to Create Items | 1Password Developer Documentation"