Error 409 while updating contact's main company

Hello,
I have a custom app that updates the contact’s info when they create a ticket and during that update the company_id is changed so that the contact’s main company is changed.

When the updated company is not yet linked as the main or one of the other companies of the contact, they are updated properly, but when the updated company already exist as an other company of the contact I get this error 409 :

{
“description”: “Validation failed”,
“errors”: [
{
“field”: “user_companies.company_id”,
“message”: “It should be a unique value”,
“code”: “duplicate_value”
},
{
“field”: “default_user_company.company_id”,
“message”: “It should be a unique value”,
“code”: “duplicate_value”
},
{
“field”: “other_companies”,
“message”: “There are no records matching the ids: ‘7000047649’”,
“code”: “invalid_value”
}
]
}

How can I update the main company of a contact ?

Thanks.