Adding an element using the API

alex_u13
alex_u13
Community Member

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_leo
    ag_leo
    1Password Alumni

    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.

This discussion has been closed.