Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields not returned by ItemsAPI get #114

Open
dillon-brock opened this issue Nov 27, 2024 · 1 comment
Open

Fields not returned by ItemsAPI get #114

dillon-brock opened this issue Nov 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dillon-brock
Copy link

dillon-brock commented Nov 27, 2024

Scenario & Reproduction Steps

I have a single item in a vault, which is a Secure Note containing a JSON blob. I'm attempting to use opClient.items.get(vaultId, itemId) to retrieve the value in the note. This is the relevant part of my code:

  const vaultId = process.env[`${env.toUpperCase()}_SENDGRID_VAULT_ID`]!;
  const itemId = process.env[`${env.toUpperCase()}_SENDGRID_ITEM_ID`]!;
  
  const item = await onepasswordClient.items.get(vaultId, itemId);
  const notesField = item.fields?.find(field => field.id == 'notesPlain');

  console.log('ITEM:', item)

  if (!notesField?.value) {
    throw new Error('Notes field not found or empty');
  }

  const onePasswordParameters = JSON.parse(notesField.value) as Record<string, string>;

Actual Behavior

When I use the CLI to get the item (with the --format json flag), I see:

{
  "id": "xxxxxxx",
  "title": "Secure Note",
  "version": 2,
  "vault": {
    "id": "xxxxxx",
    "name": "Operations"
  },
  "category": "SECURE_NOTE",
  "last_edited_by": "xxxxxx",
  "created_at": "2024-11-27T04:08:58Z",
  "updated_at": "2024-11-27T20:12:51Z",
  "additional_information": "{",
  "fields": [
    {
      "id": "notesPlain",
      "type": "STRING",
      "purpose": "NOTES",
      "label": "notesPlain",
      "value": "{\n  \"template_1\": \"first_template_id\",\n  \"template_2\": \"second_template_id\"\n}",
      "reference": "op://Operations/Secure Note/notesPlain"
    }
  ]
}

And without the json flag, I see:

ID:         xxxxx
Title:       Secure Note
Vault:       Operations (xxxxxxx)
Created:     16 hours ago
Updated:     29 minutes ago by Dillon Brock
Favorite:    false
Version:     2
Category:    SECURE_NOTE
Fields:
  notesPlain:    {
                   "template_1": "first_template_id",
                   "template_2": "second_template_id"
                 }

However, when I log the item in my code, I see the following:

{
  id: 'xxxxxx',
  title: 'Secure Note',
  category: 'SecureNote',
  vaultId: 'xxxxxxxx',
  fields: [],
  sections: [],
  tags: [],
  websites: [],
  version: 2
}

Expected Behavior

I would expect the same fields returned by the CLI to be returned by the SDK. The item is clearly defined and is being correctly fetched from 1Password, but the fields are just empty.

SDK version

0.1.2 (downgraded after first encountering the issue on 0.1.4)

Additional information

I'm initializing my client using the createClient method like so:

  const onepasswordClient = await createClient({
    auth: process.env.OP_SERVICE_ACCOUNT_TOKEN!,
    integrationName: "my_integration",
    integrationVersion: "1.0.0",
  });
@dillon-brock dillon-brock added the bug Something isn't working label Nov 27, 2024
@MOmarMiraj
Copy link
Contributor

Hello @dillon-brock, Getting and updating secure notes of items is not currently supported by the 1Password SDKs, we will look into adding support for this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants