Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
Former Member
2 years agoConnect API cannot add or edit new items
Using both python3 and curl, I can retrieve items from the connect API (built using docker compose method, pulling latest) using curl:
curl -X "GET" "http://localhost:8080/v1/vaults/${VAULT_ID}/items/${ITEM_ID} -H "Accept: application/json" -H 'Content-Type: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}"
returns valid information:
{
"category": "LOGIN",
"createdAt": "2023-06-05T22:18:27Z",
"fields": [
{
"id": "username",
"label": "username",
"purpose": "USERNAME",
"type": "STRING",
"value": "someusername"
},
(...)
I also get this if using requests.get in python3.
However, trying to either add a new item or update this one above produces the following response, no matter what I try, using both curl and ptyhon requests:
{"status":400,"message":"Invalid request body or parameter"}
My request for updating a password:
updatePasswordReq=requests.patch(
"http://localhost:8080/v1/vaults/redactedvaultid/items/redacteditemid",
headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': f'Bearer ' + opapikey
},
json={
"op": "replace",
"path": "/fields/password/value",
"value": "someP@55w0rdHere"
}
}
)
My request for adding a new item to the vault:
```
updatePasswordReq=requests.post(
"http://localhost:8080/v1/vaults/redactedvaultid/items",
headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': f'Bearer ' + opapikey
},
json={
"title": "new password test item",
"category": "LOGIN",
"fields": [
{
"value": "someusername",
"purpose": "USERNAME"
},
{
"purpose": "PASSWORD",
"generate": "False",
"value": "someP@55w0rdHere"
}
]
}
}
}
)
```
I have tried using both "json" and "data" in the request.
I need to get one of these two methods working (preferably using patch to update an entry) - Can anybody see what I might be doing wrong? I can provide more information if something is deficient. Thank you!
1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Rocky Linux 8
Browser:_ Not Provided
- michael_c_1P
1Password Team
Hi,
To get this to work using the code sample you provide, you just need to wrap the json request body in square braces, as follows:
json=[
{
"op": "replace",
"path": "/fields/password/value",
"value": "someP@55w0rdHere"
}
]
- Former Member
That works! Thank you.