Fetching document filepath

jamesstidard
jamesstidard
Community Member

Hi,

I was wondering if it's possible (maybe I just missed it while scanning) to get the file path of a document / related file through the cli. I would like to replace some of my build scripts to use things like pem keys attached to my items. I seem to be able to navigate to a documents meta data but I can't find something that looks like a path to me in there.

Thanks.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • cohix
    cohix
    1Password Alumni

    Hey @jamesstidard thanks for writing in! Let's see if we can figure this out.

    First off, we suggest using the tool jq to help with parsing JSON when using the CLI.

    If we look at an item with a related file, the JSON comes out to this:

    {
      "overview": {
        "ainfo": "a username",
        "ps": 48,
        "title": "Example Item With Link"
      },
      "details": {
        "fields": [
          {
            [...]
          }
        ],
        "sections": [
          {
            "fields": [
              {
                "k": "reference",
                "n": "8DE2DFB5CE3245FFB7620A26007A659A",
                "t": "somefile.pdf",
                "v": "hggyclcrabhfzahpwpfyw4e6eu"
              }
            ],
            "name": "linked items",
            "title": "Related Items"
          }
          [...]
    

    So, we have the details object, with an array of sections inside. One of those sections has the title "Related Items". Each of the "fields" in that sections is a related item. The "v" field in each of those objects is the UUID of the document that you can download.

    Using jq, we can filter down to get all of the related item UUIDs:

    op get item [uuid or title] | jq '.details.sections[] | select(.title=="Related Items") | .fields[] | .v'

    That will allow you to find the UUIDs of each related item, and from there you can use op get document to download each item:

    op get document [uuid] > filename.extension

    I hope that helps, please let me know if you have any questions!

  • jamesstidard
    jamesstidard
    Community Member

    @cohix Ah, perfect. I was soo close :). Thank you.

    I guess as part of the script I can pip that into a temp file and delete it after use if there's no direct file path available.

    Thanks again.

  • cohix
    cohix
    1Password Alumni

    @jamesstidard Not a problem! I'd love to hear more about your use-case, if there's any details you'd like to share.

  • jamesstidard
    jamesstidard
    Community Member

    @cohix I've not got anything written yet, so I can't share any interesting scripts. But I was looking at putting any authentication tokens/pem files I have laying around on my hard drive into 1Password.

    few reasons:

    • If I'm working with other developers I could potentially write deployment scripts in such a way that they are used from a shared vault.
    • I have multiple machines and it's a faff to keep them all up to date with token.
    • I'm pretty sure things like pem keys are unencrpyted (seeing as it doesn't require a password to use) so probably safer to have them in 1Password.

    I kind of assumed that's what the cli was released for, but maybe there's some use cases I'm missing out on.

  • cohix
    cohix
    1Password Alumni

    @jamesstidard those are some fantastic use cases, exactly the sort of thing we love to see :) feel free to share any scripts you come up with here! You can also email me (connor at agilebits.com) if you want help developing any of them!

This discussion has been closed.