connect icon indicating copy to clipboard operation
connect copied to clipboard

Unable to update a subset of item attributes

Open mega-nick opened this issue 2 years ago • 1 comments

Your environment

Chart Version: 1.10.0 Helm Version: 3.11.1 Kubernetes Version: v1.24.9 Docker Compose: v2.15.1

What happened?

I used PATCH /v1/vaults/{vaultUUID}/items/{itemUUID} as found in the API reference but got a 400 response code when using the 1Password connect server deployed via both the Docker Compose example and the connect server Helm chart with Minikube.

I've ran curl -i -X PATCH $OP_CONNECT_HOST/v1/vaults/$OP_VAULT/items/$OP_ITEM_ID -H "Content-Type: application\json" -H "Authorization: Bearer $OP_CONNECT_TOKEN" -d "{ "op":"replace", "path":"/title", "value":"hello-world" }" against both deployments which returned a 400. I've also tried this with different paths like title, /fields/username, /fields/username/label which have all returned 400 as well.

On both deployments of the 1Password Connect server I was successfully able get and delete items from the vault which makes me think the token in use is fine.

What did you expect to happen?

I expected to update part of the 1Password item.

Steps to reproduce

  1. Setup 1Password connect server using either Helm or Docker Compose
  2. Replace a subset of a 1Password item attributes using PATCH /v1/vaults/{vaultUUID}/items/{itemUUID}

Notes & Logs

Vault ID and Item ID have been replaced with X

compose-op-connect-api-1   | {"log_message":"(I) PATCH /v1/vaults/X/items/X","timestamp":"2023-03-01T16:34:11.896995668Z","level":3,"scope":{"request_id":"3f2a15c4-953a-424b-ba6e-f38ff52f461d"}}

compose-op-connect-api-1   | {"log_message":"(I) PATCH /v1/vaults/X/items/X completed (400: Bad Request) in 31ms","timestamp":"2023-03-01T16:34:11.928466168Z","level":3,"scope":{"request_id":"3f2a15c4-953a-424b-ba6e-f38ff52f461d"}}
{"status":400,"message":"Invalid request body or parameter"}

mega-nick avatar Mar 01 '23 20:03 mega-nick

This is not a Connect bug, but an error in how you send the request.

The top-level type of a JSON patch is an array, but you are posting a single object. Moreover, your curl example uses double quotes around the JSON string, which means the double quotes in the value are not sent to the server.

This works fine for me; the following changed your curl command to send an array and to use single quotes around the JSON string so the value includes the double quotes.

curl -i -X PATCH $OP_CONNECT_HOST/v1/vaults/$OP_VAULT/items/$OP_ITEM_ID \
    -H "Content-Type: application\json" \
    -H "Authorization: Bearer $OP_CONNECT_TOKEN" \
    -d '[ { "op": "replace", "path": "/title", "value": "hello-world" } ]'

mjpieters avatar Dec 16 '23 15:12 mjpieters