Adding a new ItemField belonging to a section

Hey.

I want to add a new ItemField to the Item. This ItemField must belong to an preexisting Section (if I could create a Section and an ItemField within a single request that would be even better!).

I browsed through the documentation and studied the Swagger, spent some time experimenting but to no avail.

HTTP Method: PATCH
URL: http://localhost:8080/v1/vaults/{vaultId}/items/{itemId}

Payload:
[
    {
        "op": "add",
        "path": "/fields",
        "value": {
            "label": "dupa-label",
            "type": "string",
            "value": "dupa-value",
            "section": {
                "id": "Section_i25ggti7ffjjhqxvwsous36ute",
                "label": "dupa"    
            }
        }
    }
]

Response:

...
fields: [
        {
            "id": "5truufol57nin6vjupkkwgddei",
            "type": "STRING",
            "label": "dupa-label",
            "value": "dupa-value"
        }
]
...

Obviously when I GET for this item details there is a section existing:

...
sections: [
        {
            "id": "i25ggti7ffjjhqxvwsous36ute",
            "label": "dupa"
        }
]
...

I also tried setting section.id to an id (without Section_ prefix) - didn't work.

How should I do it?


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

Comments

  • Nhat_NguyenNhat_Nguyen

    Team Member

    Hello @mariomonti, Thank you very much for reaching out to us. We only need the ID of the section to add a new field to an existing section and we also need to use replace to add your field to an existing section. So the steps to add a new field to a section is this.

    1. Create a section.
    2. Create a new field.
    3. Add the new field to our section with replace
    [
      {
        "op": "replace",
        "path": "/fields/5truufol57nin6vjupkkwgddei",
        "value": {
          "label": "dupa-label",
          "type": "string",
          "value": "dupa-label",
          "section": {
            "id": "i25ggti7ffjjhqxvwsous36ute",
            "label": "dupa"
          }
        }
      }
    ]
    

    I hope this help. Please let me know if you need more information.

Leave a Comment

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