Forum Discussion

Former Member's avatar
Former Member
4 years ago

Failed to create item: invalid JSON

Hi Team,
We've been using the 1Password CLI for quite some time, but are now trying to switch to CLIv2
In doing that, we've discovered some really odd behaviour, making it impossible for us to create new items.
Over the course of about 4 hours I've now managed to distill our script down to the smallest size to show the error we're experiencing.
The first call to op works, the second call gives us an error
What we're originally trying is parsing a CSV file with usernames & passwords and then adding those into our vault.
You will be able to see, that in my script I'm not even using the Username & Password variables I'm getting from my CSV file.
However, as soon as the script is inside a

while IFS=, read -r Username Password
do
....
done < ${CSVFile}

loop, we only get
[ERROR] 2022/04/22 14:42:37 Failed to create item: invalid JSON

from the script.

I will attach: The script, the csv file, the output.
Nevermind, I'm unable to attach the files, so I'll paste them in here

I am calling my script with the following parameters:

bash -x ./optest.sh test.csv

I'd be interested to see why this is happening.

================================

optest.sh

#!/bin/bash

CSVFile=$1

op item create --debug --category=login --title="Beginning" --vault="HARDCODEDVAULTIDFORTESTING" \
--url=https://www.acme.com/login --generate-password=20,letters,digits \
username=mailto:jane.doe@acme.com \
'Test Field 1=my test secret' --session "HARDCODEDSESSIONTOKENFORTESTING"

# Read from CSVFile, Splitting by "," separating into Variables
while IFS=, read -r Username Password; do
echo "Username: ${Username}"
echo "Password: ${Password}"
op item create --debug --title="WhileLoop" --category=login --vault="HARDCODEDVAULTIDFORTESTING" \
--url=https://www.acme.com/login --generate-password=20,letters,digits \
username=mailto:jane.doe@acme.com \
'Test Field 1=my test secret' --session "HARDCODEDSESSIONTOKENFORTESTING"
exit 0
done < ${CSVFile}

================================

test.csv

username,password

================================

script call & output

vagrant@ubuntu:~$ bash -x ./optest.sh test.csv

  • CSVFile=test.csv
  • op item create --debug --category=login --title=Beginning --vault=HARDCODEDVAULTIDFORTESTING --url=https://www.acme.com/login --generate-password=20,letters,digits username=mailto:jane.doe@acme.com 'Test Field 1=my test secret' --session HARDCODEDSESSIONTOKENFORTESTING ID: RANDOMID Title: Beginning Vault: HARDCODEDVAULTIDFORTESTING Created: now Updated: now Favorite: false Version: 0 Category: LOGIN Fields: username: mailto:jane.doe@acme.com password: A3Ztwsn4LWfFdBTuTwEh Test Field 1: my test secret URLs: : https://www.acme.com/login (primary) Additional Information: mailto:jane.doe@acme.com
  • IFS=,
  • read -r Username Password
  • echo 'Username: username' Username: username
  • echo 'Password: password' Password: password
  • op item create --debug --title=WhileLoop --category=login --vault=HARDCODEDVAULTIDFORTESTING --url=https://www.acme.com/login --generate-password=20,letters,digits username=mailto:jane.doe@acme.com 'Test Field 1=my test secret' --session HARDCODEDSESSIONTOKENFORTESTING [ERROR] 2022/04/22 14:51:59 Failed to create item: invalid JSON
  • exit 0

================================

Thanks for taking a look.

Cheers,
Dominik


1Password Version: 2.0.2
Extension Version: Not Provided
OS Version: Ubuntu 20.04

15 Replies