Cannot create an item from template and stdin at the same time

Bhaasha
Bhaasha
Community Member

Hi,
In a little shell script, I extract the data of the source item, then create a temporary template.json file and then I create the item using the template.

My problem is that my script fail with the following error:
> unable to process line 1: Cannot create an item from template and stdin at the same time

But my template is valid, and if I run manually the create command in my terminal, the item is successfully created!

Do you have any idea why my script fail when running the same command in the terminal works?
Thanks for the help!

Ben

PS1: I'm using 1Password 8.10.7 with 1Password-cli 2.18.0
PS2: Here is the script:

#!/bin/sh

# Source Vault in which we get the data
sourceVaultId="ENTER_SOURCE_VAULT_ID"
# Destination Vault in which we copy the data if they don't exist already
destVaultId="ENTER_DEST_VAULT_ID"

op items list --vault $destVaultId --format=json | jq -c -r '.[]' | while read element
do
  # write the element in a temporary json file
  echo $element >> element.json

  # extract item data (id, username, password, title, tags and urls)
  id=$(jq -r --compact-output '.id' element.json)
  username=$(op item get $id --fields label=username)
  password=$(op item get $id --fields label=password)
  title=$(jq -r --compact-output '.title' element.json)
  tags=$(jq -r --compact-output '.tags' element.json)
  urls=$(jq -r --compact-output '.urls' element.json)

  # fill an item template and write it in a temporary json file
  template="
  {
    \"title\": \"$title\",
    \"tags\": $tags,
    \"category\": \"LOGIN\",
    \"urls\": $urls,
    \"vault\": {\"id\": \"$destVaultId\"},
    \"fields\": [
        {\"id\": \"username\", \"type\": \"STRING\", \"purpose\": \"USERNAME\", \"label\": \"username\", \"value\": \"$username\"},
        {\"id\": \"password\", \"type\": \"CONCEALED\", \"purpose\": \"PASSWORD\", \"label\": \"password\", \"value\": \"$password\"}
    ]
  }";
  echo $template >> ./template.json

  # create the item from the temporary template json file
  op item create --template=template.json # the script fail here but running this same cmd in terminal works correctly...
  #op item delete $id

  # remove the temporary files
  rm element.json
  #rm template.json
done

1Password Version: 8.10.7
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided
Referrer: forum-search:Cannot create an item from template and stdin at the same time

Comments

  • Hi @Bhaasha !

    This is a known issue, and the easiest solution is to pipe the file into the item create command: cat template.json | op item create. We are looking into a solution for this and will let you know when we have a fix.

    Thank you!
    Amanda

This discussion has been closed.