# How do you add an associated organization to a contact using REST API?

**URL:** <https://www.virtocommerce.org/t/how-do-you-add-an-associated-organization-to-a-contact-using-rest-api/775>\
**Category:** Uncategorized\
**Created:** [April 15, 2025, 4:41pm UTC](https://www.virtocommerce.org/t/how-do-you-add-an-associated-organization-to-a-contact-using-rest-api/775 "2025-04-15T16:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swett-Hub](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/swett-hub/32/2045_2.png) [@Swett-Hub](https://www.virtocommerce.org/u/Swett-Hub)\
**Post date:** [April 15, 2025, 4:41pm UTC](https://www.virtocommerce.org/t/how-do-you-add-an-associated-organization-to-a-contact-using-rest-api/775/1 "2025-04-15T16:41:02Z")

</div>

I have an existing contact and want to add an organization to the contact’s “Associated company(ies)”. I tried to use the following REST API endpoint:

/api/contacts

I used the PUT method to send the following body payload:

{  
“id”: “307f4f05-6bb8-4827-bffc-9ea45ca927ae”,  
“associatedOrganizations”: [  
“a59aea58-43c9-441b-9947-a9e00afa9296”  
]  
}

This ended up completely deleting my contact. And it return a “204 No Content” response – apparently because the contact had gotten deleted and there was no contact content to return. The admin portal UI confirmed that it blew away my contact.

Two questions:

How do I modify the associatedOrganizations lists via REST API?

For that matter, how do I update any single contact field via the REST API?

---

<div class="post-metadata">

**Author:** ![OlegoO](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/olegoo/32/27_2.png) [@OlegoO](https://www.virtocommerce.org/u/OlegoO)\
**Post date:** [May 5, 2025, 11:00am UTC](https://www.virtocommerce.org/t/how-do-you-add-an-associated-organization-to-a-contact-using-rest-api/775/2 "2025-05-05T11:00:26Z")

</div>

[Virto Commerce modules v3.829.0](https://github.com/VirtoCommerce/vc-module-customer/releases/tag/3.829.0) added support for partial updates for entities using PATCH endpoint.

New methods were added to platform API:

PATCH api/members/{id}  
PATCH api/contacts/{id}  
PATCH api/organizations/{id}  
All of them receive a special json object that describes the operations performed on the fields.

Example JSON Patch Request

```json
[
  { "op": "add", "path": "/newField", "value": "New Value" },
  { "op": "remove", "path": "/oldField" },
  { "op": "replace", "path": "/existingField", "value": "Updated Value" },
  { "op": "move", "from": "/tempField", "path": "/finalField" },
  { "op": "copy", "from": "/sourceField", "path": "/destinationField" },
  { "op": "test", "path": "/testField", "value": "Expected Value" }
]

```

add - to add an element to an array  
remove - to remove an element from an array  
replace - to change value in the field

More about at the article [JsonPatch in ASP.NET Core web API | Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-8.0)

For example, to update the member’s “MiddleName” field, such a request is sufficient:

```json
[
    {
        "op": "replace",
        "path": "/middleName",
        "value": "Mishel"
    }
]

```

To add new phone to the pones array (it is necessary to specify the index, it can be max as array size)

```json
[
    {
        "op": "add",
        "path": "/phones/0",
        "value": "+79995558545"
    }
]

```

To remove

```json
[
    {
        "op": "remove",
        "path": "/phones/1"
    }
]

```

Also it possible to add a new object to object-arrays

```json
[
    {
        "op": "add",
        "path": "/addresses/1",
        "value": {
            "addressType": "BillingAndShipping",
            "name": "ESP, Valencia, c/ Eucaliptus 10",
            "organization": "",
            "countryCode": "ESP",
            "countryName": "Spain",
            "city": "Valencia",
            "postalCode": "44375",
            "zip": null,
            "line1": "c/ Eucaliptus 10",
            "line2": "pta. 10",
            "regionId": "",
            "regionName": null,
            "firstName": "Ivan",
            "middleName": null,
            "lastName": "Petrov",
            "phone": "",
            "email": "test@test.com",
            "outerId": null,
            "isDefault": false,
            "description": null
        }
    }
]

```

We recommend to use JSON patch builders to simplify usage of PATCH [https://json-patch-builder-online.github.io/](https://json-patch-builder-online.github.io/)
