1Password CLI: Failed to create item: invalid JSON

Options
sal65535
sal65535
Community Member

I'm trying to create a 1Password entry in my vault from a Symfony 4.2 (PHP 7.4) application using the Process component.

The command run from the Process component is: op item create --category='LOGIN' --vault='Vault test' --title='entryTitle' --generate-password=10,letters,digits --tags='My/Awesome/Tag' --url='https://1password.com' username='mysuperusername'

The error thrown by the 1Password CLI is: "Failed to create item: invalid JSON".

The command runs successfully if run directly from my terminal.
I'm using the 1Password CLI version 2.19.0.

The PHP 7.4 code run is below:

$process = new Process([
            'op', 'item', 'create',
            '--category', $category,
            '--vault', $vault,
            '--title', $title,
            '--generate-password=16,letters,digits',
            '--tags', $tag,
            '--url', $url,
            'username=' . $username,
            'Codice monouso[otp]=' . $otpSecret,
            'Note[text]=' . $notes
            ]
        );

        $process->run();

        if (!$process->isSuccessful()) {
            $errOut = trim($process->getErrorOutput());
            throw new \RuntimeException(
                "OnePassword returned: {$process->getExitCode()}."
                . "\nError: ({$errOut})."
                . "\nCommand executed: \"{$process->getCommandLine()}\"."
            );
        }

The error displayed from the Symfony application is:
Can't create the 1Password entry, please create it manually. OnePassword returned: 1. Error: ([ERROR] 2023/08/03 10:47:10 Failed to create item: invalid JSON). Command executed: "op item create --category='LOGIN' --vault='Vault test' --title='entryTitle' --generate-password=10,letters,digits --tags='My/Awesome/Tag' --url='https://1password.com' username='mysuperusername'".


1Password Version: 8.10.9
Extension Version: 2.13.0
OS Version: Ubuntu 22.04.2 LTS
Browser: Chrome

Comments

  • sal65535
    sal65535
    Community Member
    edited August 2023
    Options

    Solved: just put $process->setPty(true); before $process->run();.
    1Password CLI misses an option like --no-interactive which disables input source checks, so the script has to emulate an interactive terminal running the process in PTY mode (TTY works too).

This discussion has been closed.