templateUuid error when trying to create secret via Ruby SDK

sshipwaysshipway
Community Member

I am trying to create a new Secret in a 1Password vault via the Connect API (container 1.5.1), using the Ruby gem SDK (0.1.3)

I am calling the api with:

item = op.create_item(vault_id: vaultid, body: attributes)

...after first verifying I have successfully connected, and obtaining the Vault ID from other calls. However, this is always giving the response:

POST https://myhostnameisinhere/v1/vaults/vaultidishere/items: 400 - Validation: (validateVaultItem failed to Validate), Couldn't validate the item: "[ItemValidator] has found 1 errors, 0 warnings: \nErrors:{1. Required field \"item.templateUuid\" not found}"

This would seem to indicate that a templateUuid parameter is required; however, what is this? It is not mentioned in the API documentation, and even adding it to the passed attributes structure doesn't help.

This is the structure I am passing:

        attributes = {
          title: secretname,
          tags: [
            "api"
          ],
          vault: {
            id: vaultid
          },
          category: "LOGIN",
          fields: [
            {
              id: "username",
              type: "STRING"
              purpose: "USERNAME",
              label: "username",
              value: username,
            },
            {
              id: "password",
              type: "CONCEALED",
              purpose: "PASSWORD",
              label: "password",
              value: newpass,
            },
            {
              id: "notesPlain",
              type: "STRING",
              purpose: "NOTES",
              label: "notesPlain",
              value: "Created by API"
            }
          ]
        }

What am I missing here?


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

Comments

  • Jillian_1PJillian_1P

    Team Member

    Hi there,

    We do not currently have any officially supported Ruby SDK for connect. However, the error you are receiving looks to be indicating that you are not supplying a category (the templateUuid refers to the item category) for your 1Password item, however from your example it appears you are supplying this, which is odd.

    Can you perhaps share with us which third party repo you are using so we can further look into this?

  • sshipwaysshipway
    Community Member

    This is the one I'm using ( from @partydrone )
    https://1password.community/discussion/124960/announcing-ruby-gem-for-1password-connect-api
    https://github.com/partydrone/connect-sdk-ruby

    I will log a ticket in that github repo as well (I had thought it was an official SDK so posted here)

  • sshipwaysshipway
    Community Member

    @Jillian_1P - Thanks for taking a look.
    I read the 1P API documentation here - https://developer.1password.com/docs/connect/connect-api-reference/#add-an-item
    The Ruby SDK is just a wrapper for the API, and I pass it the same JSON block (see above).
    I pass a Category parameter, same as in the documentation, but not a templateUuid parameter - I take it that this is the same thing?

    It's not clear, but am I passing the Fields array correctly? I am not sure if you need id/type/purpose/value/label to all be set, particularly for username, password and notes. Also there is inconsistency in that the Item object example in the doc shows these fields with id/type/label defined but the Field object definition in the doc seems in indicate that Type is not required if you have Purpose, and Id and Label are not mentioned at all.

    If this is the cause, then the error message being generated is a bit misleading

  • sshipwaysshipway
    Community Member

    I have tried creating with minimal Fields info in the post body (omitting id/type/label ) but still same error

  • Jillian_1PJillian_1P

    Team Member
    edited May 31

    Hi again,

    We've tested your json by submitting it directly to Connect via an api request and the item was created successfully on our end. We dug a little deeper and tested the Ruby SDK and were able to to replicate your issue. It looks as if the Ruby SDK is sending connect an empty request body on POST. Your issue has shown us that we need better validation messages in this instance, so we will make an internal issue to work on this.

    Where we don't own this repo, this will need to be resolved by the owner of the Ruby SDK, though I see you've already made an issue there.

    Lastly, when creating a field only the id and type are required.

    Please let us know if we can help with anything else.

    Cheers

  • sshipwaysshipway
    Community Member

    Many thanks for the help. Hopefully the SDK maintainer will fix this fairly large problem soon.

    It would be good if, in the future some time, there were 1P-supported SDK made available for popular languages such as Ruby, Perl, Java, Php, etc

  • sshipwaysshipway
    Community Member
    edited June 1

    Problem solved! Details here for the benefit of anyone else in the future.
    This was insufficient documentation in the ruby SDK (or possibly insufficient User IQ in myself?). The problem here was the way arguments were passed to create_item()
    Rather than pass the attributes using
    create_item(vault_id: vaultid,body: attributes)
    they should instead have been passed as individual parameters
    create_item(vault_id: vaultid, title: title, tags: tagarray, fields: fieldarray, category: "LOGIN" )
    calling the function like this and it all works. Other calls also require parameters to be given in this way rather than as a single hash.
    The update_item() function is broken however (SDK 0.1.3) and needs a fix in the library, see issues in the git repo.

  • eddy_1Peddy_1P

    Team Member

    Hey @sshipway,

    Glad to hear that your problem was solved.
    As a suggestion, you can raise the documentation problem as a separate issue and provide the example that works. Or even better, maybe they can enhance the function to support the signature they give as an example.

    As for making Connect SDKs for other programming languages, we are aware that we can further expand the number of integrations available for Connect: from SDKs, to infrastructure integrations and CI/CD pipelines. We want folks to be able to easily adopt Connect in their environment.
    With that said, we will definitely let you know when we make new SDKs for other programming languages 😊

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file