Level up your business security with free, on-demand training and certification. Explore 1Password Academy today →
Forum Discussion
Anonymous
2 years agoCLI still has a bug when running "op create" programmatically
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/1289...
1passwordMember
1 year agoNew Contributor
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.