Can I use curl update my 1password items with api connect server ?

xinwen
xinwen
Community Member
edited February 2022 in Secrets Automation

Hi ,
I built an API connecting server, it looks like my connecting server works as expected and I'm able to get my item details by curl successfully

curl -H "Authorization: Bearer ${ONEPASSWORD_TOKEN}" -H "Content-Type: application/json"  \
http://onepassword-connect.onepassword.svc.cluster.local:8080/v1/vaults/${OP_VAULT_ID}/items/${OP_PUBLIC_ITEM_ID}
{
  "id": "<myitemid>",
  "title": "My Key - base64",
  "version": 60,
  "vault": {
    "id": "<myvaultid>"
  },
  "category": "SECURE_NOTE",
  "lastEditedBy": "H5JL3QWPHVBLJJERL6Y7PRZMFQ",
  "createdAt": "2021-10-11T08:48:47Z",
  "updatedAt": "2021-10-26T08:31:12Z",
  "sections": [
    {
      "id": "add more"
    },
    {
      "id": "linked items",
      "label": "Related Items"
    }
  ],
  "fields": [
    {
      "id": "notesPlain",
      "type": "STRING",
      "purpose": "NOTES",
      "label": "notesPlain",
      "value": "mytest"
    }
  ]
}

Then I tried to update my items by using PUT method , yet it failed and gave me the following error message

        {"status":400,"message":"Invalid request body or parameter"}

My command used is

curl -H "Authorization: Bearer ${ONEPASSWORD_TOKEN}" -H "Content-Type: application/json"  -X PUT  -d @key.json \
http://onepassword-connect.onepassword.svc.cluster.local:8080/v1/vaults/${OP_VAULT_ID}/items/${OP_PUBLIC_ITEM_ID}

key.json

{
  "id": "<myitemid>",
  "title": "My Key - base64",
  "version": 60,
  "vault": {
    "id": "<myvaultid>"
  },
  "category": "SECURE_NOTE",
  "lastEditedBy": "H5JL3QWPHVBLJJERL6Y7PRZMFQ",
  "createdAt": "2021-10-11T08:48:47Z",
  "updatedAt": "2021-10-26T08:31:12Z",
  "sections": [
    {
      "id": "add more"
    },
    {
      "id": "linked items",
      "label": "Related Items"
    }
  ],
  "fields": [
    {
      "id": "notesPlain",
      "type": "STRING",
      "purpose": "NOTES",
      "label": "notesPlain",
      "value": "mytest---------------------------------mytest"
    }
  ]
}

I tried to used PATCH method, it failed as well with the same error

     {"status":400,"message":"Invalid request body or parameter"} 

My command used is :

curl -H "Authorization: Bearer ${ONEPASSWORD_TOKEN}" -H "Content-Type: application/json"  -X PATCH  -d @patch.json \
http://onepassword-connect.onepassword.svc.cluster.local:8080/v1/vaults/${OP_VAULT_ID}/items/${OP_PUBLIC_ITEM_ID}

patch.json

'{ "op": "replace", "path": "/title", "value": "My New TITLE" }'  

My helm chart is 1.7.0 ,my app version is 1.5.0

I did some search and got https://1password.community/discussion/120695/adding-an-element-using-the-api, yet I still don't know how to edit my code , Can anyone help here ? thanks


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

Comments

  • xinwen
    xinwen
    Community Member

    Anyone knows what's wrong here ? thx

  • xinwen
    xinwen
    Community Member

    this issue was fixed . there was a line break in my api token . I removed the line break , everything works as expected . Thx

This discussion has been closed.