CLI - Add an item with an url

Hello,

I try to use Bitwarden with the CLI command.
I would like to create an item and add the URI in the same time but i have Python errors.

Without the ‘uris’ part, it works fine.

bw get template item | \
jq ".name="My item" | \
.login=$(bw get template item.login | jq '.username="username" | .password="azerty" | \
.uris=$(bw get template item.login.uri | jq '.match="1" | .uri="http://toto.uri.com"') | .totp=null')" | \
jq '.organizationId="af5a45ee-fdf7-455b-8be9-ae8300a4b994"' | \
jq '.collectionIds="e3ac6bcf-f0fc-4128-b9da-ae850098cfb2"' | \
jq '.folderId="5e63171e-7498-470a-b577-ae8500617fjf"' | \
jq '.notes=null' | \
bw encode | \
bw create item && bw sync

I don’t know where it’s wrong.
Thanks for your help.

Hey there!

I’ve encountered the same problem while working on some similar CLI use case.
I could successfully assign uris by using :

 bw get template item | jq '.login.username="hi" | .login.password="heyhey" | .login.uris=[{"match": null, "uri": "https://caca.ca"}] | .collectionIds=["xxx"] | .orga
nizationId="yyy" | .name="testing3"' | bw encode | bw create item

The key to understanding this is that the “login.uris” object is a JSON array, so you need an array of “$(bw get template item.login.uri)”

To adapt your code…

bw get template item | \
jq ".name="My item" | \
.login=$(bw get template item.login | jq '.username="username" | .password="azerty" | \
.uris=[$(bw get template item.login.uri | jq '.match="1" | .uri="http://toto.uri.com"')] | .totp=null')" | \
jq '.organizationId="af5a45ee-fdf7-455b-8be9-ae8300a4b994"' | \
jq '.collectionIds="e3ac6bcf-f0fc-4128-b9da-ae850098cfb2"' | \
jq '.folderId="5e63171e-7498-470a-b577-ae8500617fjf"' | \
jq '.notes=null' | \
bw encode | \
bw create item && bw sync

If you’re encountering Python errors, you might need to check which characters to escape in your (I guess?) subprocess command parameters.