op create item Error

coffeepostal
coffeepostal
Community Member

I've been playing around with the CLI, but every time I run through the Create an item tutorial, I get this error:

[LOG] 2019/03/28 11:53:21 (ERROR) invalid character 'f' looking for beginning of object key string

The invalid character changes, depending on the values I put into the template, so I'm assuming something isn't working with the encoding?

Here is the full terminal inputs and outputs:

$ op get template login

{"notesPlain":"","sections":[],"passwordHistory":[],"fields":[{"value":"","name":"username","type":"T","designation":"username"},{"value":"","name":"password","type":"P","designation":"password"}]}

$ echo {"notesPlain": "This is some plain notes.","sections": [],"passwordHistory": [],"fields": [{"value": "tempuser","name": "username","type": "T","designation": "username"},{"value": "temp1234","name": "password","type": "P","designation": "password"}]} | op encode

e25vdGVzUGxhaW46IFRoaXMgaXMgc29tZSBwbGFpbiBub3Rlcy4sc2VjdGlvbnM6IFtdLHBhc3N3b3JkSGlzdG9yeTogW10sZmllbGRzOiBbe3ZhbHVlOiB0ZW1wdXNlcixuYW1lOiB1c2VybmFtZSx0eXBlOiBULGRlc2lnbmF0aW9uOiB1c2VybmFtZX0se3ZhbHVlOiB0ZW1wMTIzNCxuYW1lOiBwYXNzd29yZCx0eXBlOiBQLGRlc2lnbmF0aW9uOiBwYXNzd29yZH1dfQ

$ op create item login 

e25vdGVzUGxhaW46IFRoaXMgaXMgc29tZSBwbGFpbiBub3Rlcy4sc2VjdGlvbnM6IFtdLHBhc3N3b3JkSGlzdG9yeTogW10sZmllbGRzOiBbe3ZhbHVlOiB0ZW1wdXNlcixuYW1lOiB1c2VybmFtZSx0eXBlOiBULGRlc2lnbmF0aW9uOiB1c2VybmFtZX0se3ZhbHVlOiB0ZW1wMTIzNCxuYW1lOiBwYXNzd29yZCx0eXBlOiBQLGRlc2lnbmF0aW9uOiBwYXNzd29yZH1dfQ

[LOG] 2019/03/28 12:06:46 (ERROR) invalid character 'n' looking for beginning of object key string

Thanks in advance for your help!

op version: 0.5.5


1Password Version: 7.2.5
Extension Version: Not Provided
OS Version: macOS X 10.14.3
Sync Type: Not Provided

Comments

  • MrC
    MrC
    Volunteer Moderator

    @coffeepostal ,

    Single quote your JSON to protect it:

    op create item login $(echo '{"notesPlain": "This is some plain notes.","fields": [{"value": "tempuser","name": "username","type": "T","designation": "username"},{"value": "temp1234","name": "password","type": "P","designation": "password"}]}' | op encode) --title=FOOBAR2 --vault=testing
    

    For brevity, I removed the empty sections and passwordHistory arrays in the example.

  • cohix
    cohix
    1Password Alumni

    @coffeepostal most shells do not play nice with JSON being thrown around as a literal string, the quotes and spaces will often throw it off. You can do as MrC mentioned and single-quote it, or you can write to a file, ex. op get template login > login.json, edit that file, then cat login.json | op encode

    Please let me know if you have any further questions!

This discussion has been closed.