Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Error trying to create basic item #51

Closed
ap1969 opened this issue Feb 7, 2019 · 6 comments
Closed

Error trying to create basic item #51

ap1969 opened this issue Feb 7, 2019 · 6 comments

Comments

@ap1969
Copy link

ap1969 commented Feb 7, 2019

Hi,

I'm trying to create a basic item via the CLI:

bw get template item | jq '.name = "dev_mariadb_master_pvc"' | bw encode | bw create item

But doing this, I get the error:

(node:25703) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'uris' of null at Function.toView (/snapshot/cli/build/bw.js:95146:17) at Function.toView (/snapshot/cli/build/bw.js:95232:49) at create_command_CreateCommand.<anonymous> (/snapshot/cli/build/bw.js:102561:82) at Generator.next (<anonymous>) at create_command_awaiter (/snapshot/cli/build/bw.js:102511:71) at new Promise (<anonymous>) at create_command_awaiter (/snapshot/cli/build/bw.js:102507:12) at create_command_CreateCommand.createCipher (/snapshot/cli/build/bw.js:102560:16) at create_command_CreateCommand.<anonymous> (/snapshot/cli/build/bw.js:102549:39) at Generator.next (<anonymous>) (node:25703) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:25703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. root@util:~/devenv# bw get template item | jq '.name = "dev_mariadb_master_pvc"' | bw encode | bw create item (node:25773) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'uris' of null at Function.toView (/snapshot/cli/build/bw.js:95146:17) at Function.toView (/snapshot/cli/build/bw.js:95232:49) at create_command_CreateCommand.<anonymous> (/snapshot/cli/build/bw.js:102561:82) at Generator.next (<anonymous>) at create_command_awaiter (/snapshot/cli/build/bw.js:102511:71) at new Promise (<anonymous>) at create_command_awaiter (/snapshot/cli/build/bw.js:102507:12) at create_command_CreateCommand.createCipher (/snapshot/cli/build/bw.js:102560:16) at create_command_CreateCommand.<anonymous> (/snapshot/cli/build/bw.js:102549:39) at Generator.next (<anonymous>) (node:25773) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:25773) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I can create a folder fine using your documentation example:
bw get template folder | jq '.name = "My Folder"' | bw encode | bw create folder

Can you help by providing working item creation code, for a secure note, please?

Regards,
Andy

@scampi
Copy link

scampi commented Feb 4, 2020

According to #22 this is an item of type 1, to which you have to pass a list of uris. For a secure note, pass a type 2. You have to fill out the other object types too, e.g., for fields.

@yngvark
Copy link

yngvark commented Mar 11, 2020

Answer to original question:

{
  "card": null,
  "favorite": false,
  "fields": [],
  "folderId": null,
  "identity": null,
  "login": null,
  "name": "my_name",
  "notes": "my_secure_note",
  "organizationId": "some-guid",
  "secureNote": "",
  "type": 2
}

Put into a file, bwitem.json.
Use bw list items to find the organizationId.

Then run:
organizationId

cat bwitem.json | bw encode | bw create item

@michael-l-a
Copy link

michael-l-a commented Apr 29, 2020

Closed ticket too early:
BW version: 1.9.1

With organization ID, without type:

bw get template item | \
jq '.name = "Test Item" | .organizationId = "*********-****-****-****-******"' | \
bw encode | bw create item

(node:65882) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'uris' of null

With organization ID, with type:

bw get template item | \
jq '.name = "Test Item" | .type = 2 | .organizationId = "*********-****-****-****-******"' | \
bw encode | bw create item

(node:65837) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of null

@adamwojt
Copy link

adamwojt commented Feb 27, 2021

I created a wrapper with Python that can be added directly to .bashrc or .zshrc. It should work assuming you have python3 in your $PATH.
It is only for my needs so it creates simple items with login, password and name but I guess it is straight forward to modify if you know some Python.

function bwcreate() {
    local python_code=$(cat - <<EOF
import argparse;import json;import secrets;import sys
parser = argparse.ArgumentParser(description='Create bitwarden item')
required = parser.add_argument_group('required named arguments')
required.add_argument('-n', '--name', required=True, help='name of item')
required.add_argument('-l', '--login', required=True)
parser.add_argument('-p', '--password', help='auto generate if empty')
parser.add_argument('-no', '--note')
if len(sys.argv)==1:
    parser.print_help(sys.stderr)
    sys.exit(1)
args = parser.parse_args()
if not args.password:
    args.password = secrets.token_urlsafe(14)
login_data = {'username':args.login,'password':args.password}
data = {'organizationId':None,'folderId':None,'type':1,'name':args.name,'notes':args.note,'favorite':False,'fields':[],'login':None,'secureNote':None,'card':None,'identity':None}
data.update(login=login_data)
print(json.dumps(data))
EOF
    )
    json=$(python3 -c $python_code "$@")
    if (( status != 0 )); then
        return 1
    fi
    echo $json | bw encode | bw create item
}

@jimsnab
Copy link

jimsnab commented Sep 3, 2021

btw, "type" 2 at the root corresponds to "Item Types" table in reference.

The template item.secureNote also has a "type" member. It's unclear what that represents.

@eliykat
Copy link
Member

eliykat commented Sep 6, 2021

@jimsnab, the secure note type looks to be unused at the moment - it's an enum with only 1 value:

export enum SecureNoteType {
    Generic = 0,
}

You may still have to specify it when you create the item though, I'm not sure.

The other questions in this thread seem to have been discussed and resolved, and it's otherwise been inactive for some time. We use GitHub issues as a place to track bugs and other development related issues, not user support, so I'll close this.

If anyone would like help using or configuring Bitwarden, please contact our Customer Success team here: https://bitwarden.com/contact. You can also search for an answer in our help documentation or get help from other Bitwarden users on our community forums. The issue here will be closed.

@eliykat eliykat closed this as completed Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants