Skip to main content
December 6, 2023
Question

CLI still has a bug when running "op create" programmatically

  • December 6, 2023
  • 6 replies
  • 917 views

I am running "op create" programmatically and I get an error saying

[ERROR] 2023/12/06 11:47:57 invalid JSON in piped input

This was reported before https://1password.community/discussion/128994/failed-to-create-item-invalid-json, and marked as fixed, but I am using version 2.23.0 and I can still experience this.

Here's my Dart code:

const itemName = 'retrievable generated password';
final passwordCreationResult = processManager.runSync([
'op',
'item',
'create',
'--title="$itemName"',
'--category=password',
'--generate-password',
]);
print(passwordCreationResult.stdout.toString());
print(passwordCreationResult.stderr.toString());


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser: Not Provided

6 replies

December 16, 2023

I can confirm on version 2.24.0 on OSX

when I call on my command line


op item create --category=login --vault=adrastea \
--generate-password=64,letters,digits --title=postgres/nfcbox-preview

=> item will be created successfully

when I call the same command programmatically from within python I get


File "/Users/REDACTED/.pyenv/versions/3.10.6/lib/python3.10/site-packages/exec_utils/exec_utils.py", line 49, in wait
raise ExecStrictError("error while executing %s,\nstdout: %s\nstderr: %s\n" % (
exec_utils.exec_strict_error.ExecStrictError: error while executing ['op', 'item', 'create', '--category=login', '--vault=adrastea', '--generate-password=64,letters,digits', '--title=postgres/nfcbox-preview'],
stdout:
stderr: [ERROR] 2023/12/16 13:59:02 invalid JSON in piped input

I assume you find no PTY and assume STDIN mode.

December 16, 2023

Ah this can even easier be reproduced:

this works:


op item create --category=login

this does NOT work:


echo 'op item create --category=login' | bash

January 15, 2024

I am experiencing this as well. It happens when my bash script is accepting input from stdin.

Workaround is to close stdin, e.g.:

```

!/bin/bash

0<&- # Close stdin when done with it
op item create --category=login </dev/null
```

or more simply:

```

!/bin/bash

op item create --category=login </dev/null
```

January 30, 2024

Thanks @dansimau for the workaround!

eM_Jay_Be
April 11, 2024

I am also experiencing a similar issue with a project. It's not quite the same, mine involves the QProcess class in a Qt/QML app. All other commands I use work fine, including delete. Tried adding closeWriteChannel() as it seemed similar to above workarounds but to no avail. Haven't tested with edit yet.

April 19, 2024

I've encountered a similar issue while attempting to programmatically create new entries using the 'op item create' command in the 1Password CLI version 2.27.0. I'm coding the application in Java. Facing similar challenges as others, depending on how I invoke the 'op item create' command, it either times out or returns an error message stating 'invalid JSON in piped input'. I've tested on both Windows and Linux, spending an entire day troubleshooting. Eventually, I found a solution to properly use the 'op item create' command in Java.

I had to redirect the input to null output using ProcessBuilder:

java
ProcessBuilder processBuilder = new ProcessBuilder("op", "item", "create", "--category", "login", "--dry-run", "--format", "json");
Map<String, String> env = processBuilder.environment();
env.put("OP_SERVICE_ACCOUNT_TOKEN", "xxxx");
processBuilder.redirectInput(ProcessBuilder.Redirect.from(new File(System.getProperty("os.name").startsWith("Windows") ? "NUL" : "/dev/null")));
Process proc = processBuilder.start();

This resolved the issue for me.