Import output of `op list items --account ACCOUNT2 | op get item -` to a different account

austin
austin
Community Member

Using 1Password command-line tool 1.12.4.

I’ve got temporary access to a vault in ACCOUNT2 so that I can copy the entries to ACCOUNT1. They didn’t set up my account permissions to have right-click "copy item" support so that I could do this in the GUI, so I exported everything using op:

op list items --account ACCOUNT2 | op get item - > ACCOUNT2.jsonl

I did the same thing (more or less) with op list documents (there are two attached documents).

I’ve split the individual line entries into multiple single JSON files and want to create them in the new account more or less like this:

op create item --account ACCOUNT1 --vault VAULTNAME --template item1.json

This didn’t work initially because of the missing category.

So I modified it:

op create item --account ACCOUNT1 --vault VAULTNAME --template item1.json Password

This worked, but not really. It was imported as "Untitled Password", despite the fact that there is a details.title field.

So I decided to try something else:

jq '{
    notesPlain: .details.notesPlain,
    password: (.details.fields[] | select(.type == "P") | .value),
    title: .overview.title
  }' <item1.json | op create item --vault VAULTNAME --account ACCOUNT1 --template - Password

Which didn’t work because template doesn’t know how to deal with - as a name, so I changed it again:

jq '{
    notesPlain: .details.notesPlain,
    password: (.details.fields[] | select(.type == "P") | .value),
    title: .overview.title
  }' <item1.json > x.json && op create item --vault VAULTNAME --account ACCOUNT1 --template x.json Password

And that still imported it as "Untitled Password".

As it looks right now, I’m probably going to have to make a script that not only transforms the target file as the jq does above, but creates another script that will run op create item --vault VAULTNAME --account ACCOUNT1 --template x.json Password --title $title.

Is there no easier way? It seems to me that the output of op get item should be fully compatible with op create item, even if op create item ignores things like uuid, vault, etc.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: macOS 12.2

Comments

  • austin
    austin
    Community Member

    Please note that I have solved this through some effort, but the question remains.

  • Hey @austin

    With the release of V2, there's an upcoming feature where you can pipe in item JSON objs into the item create command.

    One such example that would fit your use case is:

    op item list --account ACCOUNT1 | op item get --account ACCOUNT1 - | op item create - --account ACCOUNT2
    

    What we had in mind for this feature was for ease of migrating items, and I am hoping it helps.

    This feature is being actively developed, and will likely be included in v2.0.1, so please keep an eye out if it is of interest to you!

This discussion has been closed.