# upsert_company_map

Créer une société et son équipe

## Rôle

Société + contacts + affiliations en UN appel transactionnel (tout ou rien) : `company` crée (dédup appliquée : doublon fort refusé, doublon probable = duplicateWarning), `companyId` complète une société existante. Les contacts sont affiliés à cette société avec leur rôle. Contacts : exige contacts:write.

## Accès

Scope principal : `companies:write`. Le scope ne remplace pas les gardes de visibilité, d'organisation, de module ni les scopes complémentaires des gestes composés.

[Catalogue complet](/documentation/mcp-reference/) · [Approbations](/documentation/approbations/)

## Paramètres

Le schéma ci-dessous est produit par la fonction qui enregistre les outils, y compris `idempotency_key` lorsqu'elle s'applique. Consultez les objets imbriqués dans le schéma complet.
```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "companyId": {
      "description": "Société EXISTANTE à compléter (exclusif avec company)",
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "company": {
      "description": "Société à CRÉER (exclusif avec companyId)",
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 2,
          "maxLength": 200
        },
        "ownerId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            {
              "type": "null"
            }
          ]
        },
        "sector": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "maxLength": 80
            }
          ]
        },
        "parentCompanyId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            {
              "type": "null"
            }
          ]
        },
        "siret": {
          "type": [
            "null",
            "string"
          ]
        },
        "vatNumber": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 40
            },
            {
              "type": "null"
            }
          ]
        },
        "website": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "maxLength": 200
            }
          ]
        },
        "linkedin": {
          "type": [
            "null",
            "string"
          ]
        },
        "x": {
          "type": [
            "null",
            "string"
          ]
        },
        "instagram": {
          "type": [
            "null",
            "string"
          ]
        },
        "billingAddress": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "maxLength": 300
            }
          ]
        },
        "customFields": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "maxLength": 80
          },
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 2000
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "externalCodes": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "additionalProperties": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 40,
                "pattern": "^[A-Za-z0-9._-]+$"
              }
            ]
          }
        },
        "relations": {
          "description": "#494 : natures de relation (clés de la liste d'organisation, GET /company-relations) ; remplace la liste, [] retire tout",
          "maxItems": 30,
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,39}$"
          }
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    },
    "contacts": {
      "minItems": 1,
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "firstName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "lastName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "email": {
            "type": "string",
            "format": "email",
            "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
          },
          "phone": {
            "type": "string",
            "minLength": 1,
            "maxLength": 30
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "role": {
            "type": "string",
            "enum": [
              "principal",
              "operational",
              "billing",
              "other"
            ],
            "description": "Rôle d'affiliation à la société du batch"
          }
        },
        "required": [
          "firstName",
          "lastName",
          "email",
          "role"
        ],
        "additionalProperties": false
      }
    },
    "idempotency_key": {
      "description": "Clé d'idempotence (recommandée) : rejouer la MÊME mutation avec la même clé renvoie la réponse originale sans ré-exécuter - TTL 24 h",
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    }
  },
  "additionalProperties": false
}
```


Voir les schémas complets dans /documentation/mcp.json.
