How can I update or create with OP a Login?

hayo
hayo
Community Member

I try to store login information via a bash file. How can I create or update login information in an vault?


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided
Referrer: forum-search:How can I update or create with OP a Login?

Comments

  • cohix
    cohix
    1Password Alumni

    @hayo we currently do not support updating items with op, but here are the instructions to create an item: https://support.1password.com/command-line/#create-an-item

  • hayo
    hayo
    Community Member
    edited July 2019

    Hi cohix,
    thanks. For anyone who is looking here a short script:

    delete for existing login

    uuid=$(op get item "${LOGIN_TITLE}" --vault="${VAULT_NAME}" | jq '(.uuid)' | sed 's/\"//g')
    if [ -n "$uuid" ]
    then
    op delete item $uuid
    fi

    create new login information

    login=$( op get template login )
    login_user=$( echo $login | jq --arg USER "$USER" -c '.fields[0].value = $USER ')
    login_user_pw=$( echo $login_user | jq --arg PW "$PW" -c '.fields[1].value = $PW' )
    encoded_login=$( echo $login_user_pw | op encode )

    save in vault

    op create item Login $encoded_login --title="$LOGIN_TITLE" --vault="$VAULT_NAME"
    echo '1Password Login updated for '${USER}'

  • ag_ana
    ag_ana
    1Password Alumni

    Thank you for sharing this! :+1:

  • felix_1p
    felix_1p
    1Password Alumni

    As of v0.10.0, the 1Password command line tool has a edit item command with which existing fields of an item can be updated. See https://support.1password.com/command-line-reference/#edit-item for more information!

This discussion has been closed.