> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwoty.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Mettre à jour un produit

> Mettre à jour un produit existant

## Autorisation

<ParamField header="Authorization" type="string" required>
  Jeton Bearer pour l'authentification. Format : `Bearer qwoty_your_token`
</ParamField>

## Paramètres de chemin

<ParamField path="id" type="string" required>
  UUID du produit à mettre à jour
</ParamField>

## Corps de la requête

<ParamField body="name" type="string">
  Nom du produit
</ParamField>

<ParamField body="description" type="string">
  Description du produit
</ParamField>

<ParamField body="description_inherit_from_product" type="boolean">
  Indique si la description doit être héritée du produit parent
</ParamField>

<ParamField body="primary_image_inherit_from_product" type="boolean">
  Indique si l'image principale doit être héritée du produit parent
</ParamField>

<ParamField body="reference" type="string">
  Référence interne
</ParamField>

<ParamField body="is_active" type="boolean">
  Statut actif
</ParamField>

<ParamField body="category_ids" type="array">
  UUIDs de catégories à associer au produit parent. Remplace tous les liens de
  catégories existants.
</ParamField>

<ParamField body="inventory[sku]" type="string">
  Unité de gestion des stocks (SKU)
</ParamField>

<ParamField body="settings[unit_per_pack]" type="number">
  Nombre d'unités par pack
</ParamField>

<ParamField body="accounting[ledger_account]" type="string">
  Code du compte comptable
</ParamField>

<ParamField body="identifiers[crm]" type="string">
  ID CRM externe
</ParamField>

<ParamField body="identifiers[erp]" type="string">
  ID ERP externe
</ParamField>

<ParamField body="identifiers[accounting]" type="string">
  ID comptable externe
</ParamField>

<ParamField body="shipping[weight]" type="number">
  Poids d'expédition
</ParamField>

<ParamField body="shipping[weight_unit]" type="string">
  Unité de poids d'expédition (kg, lbs)
</ParamField>

<ParamField body="shipping[height]" type="number">
  Hauteur d'expédition
</ParamField>

<ParamField body="shipping[length]" type="number">
  Longueur d'expédition
</ParamField>

<ParamField body="shipping[width]" type="number">
  Largeur d'expédition
</ParamField>

<ParamField body="shipping[length_unit]" type="string">
  Unité de longueur d'expédition (cm, in, etc.)
</ParamField>

<ParamField body="shipping[country_of_origin]" type="string">
  Pays d'origine pour l'expédition
</ParamField>

<ParamField body="shipping[harmonized_system_code]" type="string">
  Code SH pour les douanes
</ParamField>

<ParamField body="primary_image_id" type="string">
  UUID du média principal à associer à ce produit. Définir à `null` pour
  supprimer l'image principale.
</ParamField>

Les champs tels que `api_name` sont réservés à la création : ils peuvent apparaître sur la ressource mais ne peuvent pas être envoyés dans un corps PATCH (l'API retourne `400` avec un détail de validation s'ils sont inclus).

## Exemples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH https://qwoty.app/api/products/550e8400-e29b-41d4-a716-446655440000 \
    -H "Authorization: Bearer qwoty_your_token" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Updated Product Name",
      "description": "Updated description",
      "is_active": false
    }'
  ```

  ```javascript JavaScript theme={null}
  const productId = '550e8400-e29b-41d4-a716-446655440000'

  const response = await fetch(`https://qwoty.app/api/products/${productId}`, {
    method: 'PATCH',
    headers: {
      Authorization: 'Bearer qwoty_your_token',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      name: 'Updated Product Name',
      description: 'Updated description',
      is_active: false,
    }),
  })

  const data = await response.json()
  ```

  ```python Python theme={null}
  import requests

  product_id = '550e8400-e29b-41d4-a716-446655440000'

  response = requests.patch(
      f'https://qwoty.app/api/products/{product_id}',
      headers={
          'Authorization': 'Bearer qwoty_your_token',
          'Content-Type': 'application/json'
      },
      json={
          'name': 'Updated Product Name',
          'description': 'Updated description',
          'is_active': False
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Réponse

<ResponseField name="success" type="boolean">
  Indique si la requête a réussi
</ResponseField>

<ResponseField name="data" type="object">
  L'objet produit mis à jour avec tous les champs, y compris le tableau `prices`
</ResponseField>

<ResponseExample>
  ```json Réponse de succès theme={null}
  {
    "success": true,
    "data": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "product_parent_id": "660e8400-e29b-41d4-a716-446655440001",
      "workspace_id": "880e8400-e29b-41d4-a716-446655440003",
      "name": "Updated Product Name",
      "api_name": "updated_product_name",
      "reference": "PROD-001",
      "description": "Updated description",
      "description_inherit_from_product": true,
      "primary_image_inherit_from_product": true,
      "is_active": false,
      "is_default": true,
      "catalog_ids": ["770e8400-e29b-41d4-a716-446655440002"],
      "category_ids": [],
      "settings": {
        "unit_per_pack": 1,
        "product_type": "physical",
        "language_id": null,
        "unit_of_measure": null,
        "recurrence_type": "one_off"
      },
      "shipping": {
        "weight": 2.8,
        "weight_unit": "kg",
        "length": 30,
        "width": 20,
        "height": 10,
        "length_unit": "cm",
        "country_of_origin": "FR",
        "harmonized_system_code": "8471.30"
      },
      "inventory": {
        "sku": "WID-PRE-001"
      },
      "identifiers": {
        "crm": "crm_123",
        "accounting": "acc_789",
        "erp": "erp_456"
      },
      "accounting": {
        "ledger_account": "4010"
      },
      "primary_image_id": null,
      "parent_primary_image_id": null,
      "options": [],
      "prices": [
        {
          "id": "ee0e8400-e29b-41d4-a716-446655440030",
          "pricebook_id": "ff0e8400-e29b-41d4-a716-446655440031",
          "pricebook_api_name": "standard"
        }
      ],
      "created_at": "2024-12-21T10:30:00Z",
      "updated_at": "2024-12-21T14:45:00Z"
    }
  }
  ```
</ResponseExample>

## Réponses d'erreur

<ResponseExample>
  ```json Non trouvé theme={null}
  {
    "success": false,
    "error": "Product not found"
  }
  ```

  ```json Erreur de validation theme={null}
  {
    "success": false,
    "error": "Validation error",
    "details": {
      "name": "Name must be at least 2 characters"
    }
  }
  ```

  ```json Erreur de validation (champ en lecture seule) theme={null}
  {
    "error": "Validation error",
    "details": ["Field 'reference' is read-only or unknown"]
  }
  ```

  ```json Non autorisé theme={null}
  {
    "success": false,
    "error": "Invalid API token"
  }
  ```
</ResponseExample>
