Adding an element using the API

Hi!

I have a problem. I add an element using the API, but an error occurs:

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

I provide the code:

HEADERS = {'Authorization': f'Bearer {token}'}
DATA = {
    "title": "Secrets Automation Item",
    "category": "LOGIN",
    "sections": [
        {
            "label": "Security Questions",
            "id": "95cdbc3b-7742-47ec-9056-44d6af82d562"
        }
    ],
    "fields": [
        {
            "value": "wendy",
            "purpose": "USERNAME"
        },
        {
            "purpose": "PASSWORD",
            "generate": True,
            "recipe": [
                {
                    "length": 55,
                    "characterSets": [
                        "LETTERS",
                        "DIGITS"
                    ]
                }
            ]
        }]
}

items = requests.post(f'{api_url}/vaults/{vault_id}/items', headers=HEADERS, data=DATA).json()
print(items)

Tell me, please, what am I doing wrong?

I took the code for the API from the page - https://support.1password.com/connect-api-reference/.

connect-api and connect-sync are used in the latest version.


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

Comments

  • ag_leoag_leo

    Team Member

    Hi @alex_u13, thanks for reaching out!

    The issue is that recipe should not be an array. It seems like we have a typo in our API docs, we'll get that fixed, sorry about that.

    In the meantime, you can remove the array that is wrapping recipe.
    I also had to do json=DATA instead of data=DATA inside the POST request to get it to work on my end, that might be the case for you as well.

    Don't hesitate to reach out again if there's anything else that is causing you trouble.

Leave a Comment

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