Skip to main content

create

The create command creates a new object in your safe:

bsafe create (item|attachment|folder|org-collection) <encodedJson> [options]

The create command takes encoded JSON. A typical workflow for creating an object might look something like:

  1. Use the get template command (see get template) to output the appropriate JSON template for the object type.

  2. Use a command-line JSON processor like jq to manipulate the outputted template as required.

  3. Use the encode command (encode) to encode the manipulated JSON.

  4. Use the create command to create an object from the encoded JSON.

For example:

bsafe get template folder | jq '.name="My First Folder"' | bsafe encode | bsafe create folder

or

bsafe get template item | jq ".name=\"My Login Item\" | .login=$(bsafe get template item.login | jq '.username="jdoe" | .password="myp@ssword123"')" | bsafe encode | bsafe create item

Upon successful creation, the newly created object will be returned as JSON.

Create other Item types

The create command defaults to creating a Login item. Use a command-line JSON processor such as jq to change a .type= attribute to create other item types:

Name

Value

Login

.type=1

Secure Note

.type=2

Card

.type=3

Identity

.type=4

For example, the following command will create a Secure Note:

bsafe get template item | jq '.type = 2 | .secureNote.type = 0 | .notes = "Contents of my Secure Note." | .name = "My Secure Note"' | bsafe encode | bsafe create item

Note

In the above example, Secure Notes require a sub-template (.secureNote.type). You can view Item type sub-templates using bsafe get template (see get template).

See

The get template command returns the expected JSON formatting for an object:

bsafe get template (item|item.field|item.login|item.login.uri|item.card|item.identity|item.securenote|folder|collection|item-collections|org-collection)

While you can use get template to output the format to your screen, the most common use case is to pipe the output into a bsafe create operation, using a command-line JSON processor such as jq and bsafe encode (encode) to manipulate the values retrieved from the template, for example:

bsafe get template folder | jq '.name="My First Folder"' | bsafe encode | bsafe create folder

Any item.xxx template should be used as a sub-object to an item template, for example:

bsafe get template item | jq ".name=\"My Login Item\" | .login=$(bsafe get template item.login | jq '.username="jdoe" | .password="myp@ssword123"')" | bsafe encode | bsafe create item

The encode command Base 64 encodes stdin. This command is typically used in combination with a command-line JSON processor such as jq when performing create and edit operations, for example:

bsafe get template folder | jq '.name="My First Folder"' | bsafe encode | bsafe create folder
bsafe get item 7ac9cae8-5067-4faf-b6ab-acfd00e2c328 | jq '.login.password="newp@ssw0rd"' | bsafe encode | bsafe edit item 7ac9cae8-5067-4faf-b6ab-acfd00e2c328