# API : sales-targets

4 opérations REST du groupe sales-targets.

Base : `/api/v1`. [Conventions](/documentation/api-conventions/) · [Toutes les ressources](/documentation/api-reference/)

- GET /sales-targets : Objectifs individuels d'un cycle : objectif d'équipe, somme attribuée, reste, une ligne par commercial (#750)
- PUT /sales-targets : Pose, modifie ou retire (amount null) l'objectif d'un commercial sur un cycle non clos (#750)
- GET /sales-targets/mode : Mode de répartition des objectifs de l'organisation (#750)
- PUT /sales-targets/mode : Change le mode de répartition, sans réécrire aucun cycle clos (#750)
## GET /sales-targets

```json
{
  "summary": "Objectifs individuels d'un cycle : objectif d'équipe, somme attribuée, reste, une ligne par commercial (#750)",
  "tags": [
    "Objectifs"
  ],
  "parameters": [
    {
      "name": "cycleId",
      "in": "query",
      "required": true,
      "schema": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "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)$"
      }
    }
  ],
  "security": [
    {
      "oauth2": [
        "settings:write"
      ]
    },
    {
      "userSession": []
    }
  ],
  "responses": {
    "200": {
      "description": "Répartition du cycle",
      "content": {
        "application/json": {
          "schema": {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "type": "object",
            "properties": {
              "cycle": {
                "type": "object",
                "properties": {
                  "id": {
                    "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)$"
                  },
                  "label": {
                    "type": "string"
                  },
                  "startsOn": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "endsOn": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "upcoming",
                      "active",
                      "closed"
                    ]
                  }
                },
                "required": [
                  "id",
                  "label",
                  "startsOn",
                  "endsOn",
                  "status"
                ],
                "additionalProperties": false
              },
              "mode": {
                "type": "string",
                "enum": [
                  "equal",
                  "individual"
                ],
                "description": "Mode qui s'applique au cycle (figé pour un cycle clos)"
              },
              "editable": {
                "type": "boolean",
                "description": "Faux pour un cycle clos : l'historique se lit, il ne se modifie plus"
              },
              "teamTarget": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "Montant HT, deux décimales"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Somme des objectifs d'entités du cycle ; null si aucune n'en porte"
              },
              "assigned": {
                "type": "string",
                "description": "Somme des objectifs des commerciaux listés"
              },
              "remaining": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "Montant HT, deux décimales"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Objectif d'équipe moins la somme attribuée ; négatif = dépassement"
              },
              "overAllocated": {
                "type": "boolean"
              },
              "divisor": {
                "anyOf": [
                  {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Diviseur de la répartition égale ; null en mode individuel"
              },
              "sellers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "userId": {
                      "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)$"
                    },
                    "name": {
                      "type": "string"
                    },
                    "active": {
                      "type": "boolean",
                      "description": "Faux pour un commercial parti, listé en lecture s'il porte un objectif"
                    },
                    "target": {
                      "anyOf": [
                        {
                          "type": "string",
                          "description": "Montant HT, deux décimales"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Objectif tous périmètres ; null = non défini"
                    },
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "businessUnitId": {
                            "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"
                              }
                            ],
                            "description": "Null = tous périmètres"
                          },
                          "amount": {
                            "type": "string",
                            "description": "Montant HT, deux décimales"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                          },
                          "updatedBy": {
                            "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)$"
                          }
                        },
                        "required": [
                          "businessUnitId",
                          "amount",
                          "updatedAt",
                          "updatedBy"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "userId",
                    "name",
                    "active",
                    "target",
                    "entries"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "cycle",
              "mode",
              "editable",
              "teamTarget",
              "assigned",
              "remaining",
              "overAllocated",
              "divisor",
              "sellers"
            ],
            "additionalProperties": false
          }
        }
      }
    },
    "default": {
      "description": "Erreur - enveloppe problem+json (RFC 9457)",
      "content": {
        "application/problem+json": {
          "schema": {
            "$ref": "#/components/schemas/Problem"
          }
        }
      }
    }
  }
}
```

## PUT /sales-targets

```json
{
  "summary": "Pose, modifie ou retire (amount null) l'objectif d'un commercial sur un cycle non clos (#750)",
  "description": "Un dépassement de l'objectif d'équipe est signalé dans la réponse (`overAllocated`), jamais refusé. Cycle clos : 422 `not-editable`.",
  "tags": [
    "Objectifs"
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "type": "object",
          "properties": {
            "userId": {
              "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)$"
            },
            "cycleId": {
              "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)$"
            },
            "businessUnitId": {
              "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"
                }
              ]
            },
            "amount": {
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 999999999999.99
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "userId",
            "cycleId",
            "businessUnitId",
            "amount"
          ]
        }
      }
    }
  },
  "security": [
    {
      "oauth2": [
        "settings:write"
      ]
    },
    {
      "userSession": []
    }
  ],
  "responses": {
    "200": {
      "description": "Répartition du cycle après écriture",
      "content": {
        "application/json": {
          "schema": {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "type": "object",
            "properties": {
              "cycle": {
                "type": "object",
                "properties": {
                  "id": {
                    "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)$"
                  },
                  "label": {
                    "type": "string"
                  },
                  "startsOn": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "endsOn": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "upcoming",
                      "active",
                      "closed"
                    ]
                  }
                },
                "required": [
                  "id",
                  "label",
                  "startsOn",
                  "endsOn",
                  "status"
                ],
                "additionalProperties": false
              },
              "mode": {
                "type": "string",
                "enum": [
                  "equal",
                  "individual"
                ],
                "description": "Mode qui s'applique au cycle (figé pour un cycle clos)"
              },
              "editable": {
                "type": "boolean",
                "description": "Faux pour un cycle clos : l'historique se lit, il ne se modifie plus"
              },
              "teamTarget": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "Montant HT, deux décimales"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Somme des objectifs d'entités du cycle ; null si aucune n'en porte"
              },
              "assigned": {
                "type": "string",
                "description": "Somme des objectifs des commerciaux listés"
              },
              "remaining": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "Montant HT, deux décimales"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Objectif d'équipe moins la somme attribuée ; négatif = dépassement"
              },
              "overAllocated": {
                "type": "boolean"
              },
              "divisor": {
                "anyOf": [
                  {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Diviseur de la répartition égale ; null en mode individuel"
              },
              "sellers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "userId": {
                      "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)$"
                    },
                    "name": {
                      "type": "string"
                    },
                    "active": {
                      "type": "boolean",
                      "description": "Faux pour un commercial parti, listé en lecture s'il porte un objectif"
                    },
                    "target": {
                      "anyOf": [
                        {
                          "type": "string",
                          "description": "Montant HT, deux décimales"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Objectif tous périmètres ; null = non défini"
                    },
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "businessUnitId": {
                            "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"
                              }
                            ],
                            "description": "Null = tous périmètres"
                          },
                          "amount": {
                            "type": "string",
                            "description": "Montant HT, deux décimales"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                          },
                          "updatedBy": {
                            "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)$"
                          }
                        },
                        "required": [
                          "businessUnitId",
                          "amount",
                          "updatedAt",
                          "updatedBy"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "userId",
                    "name",
                    "active",
                    "target",
                    "entries"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "cycle",
              "mode",
              "editable",
              "teamTarget",
              "assigned",
              "remaining",
              "overAllocated",
              "divisor",
              "sellers"
            ],
            "additionalProperties": false
          }
        }
      }
    },
    "default": {
      "description": "Erreur - enveloppe problem+json (RFC 9457)",
      "content": {
        "application/problem+json": {
          "schema": {
            "$ref": "#/components/schemas/Problem"
          }
        }
      }
    }
  }
}
```

## GET /sales-targets/mode

```json
{
  "summary": "Mode de répartition des objectifs de l'organisation (#750)",
  "tags": [
    "Objectifs"
  ],
  "security": [
    {
      "oauth2": [
        "settings:write"
      ]
    },
    {
      "userSession": []
    }
  ],
  "responses": {
    "200": {
      "description": "Mode courant",
      "content": {
        "application/json": {
          "schema": {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "equal",
                  "individual"
                ]
              }
            },
            "required": [
              "mode"
            ],
            "additionalProperties": false
          }
        }
      }
    },
    "default": {
      "description": "Erreur - enveloppe problem+json (RFC 9457)",
      "content": {
        "application/problem+json": {
          "schema": {
            "$ref": "#/components/schemas/Problem"
          }
        }
      }
    }
  }
}
```

## PUT /sales-targets/mode

```json
{
  "summary": "Change le mode de répartition, sans réécrire aucun cycle clos (#750)",
  "tags": [
    "Objectifs"
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "equal",
                "individual"
              ]
            }
          },
          "required": [
            "mode"
          ]
        }
      }
    }
  },
  "security": [
    {
      "oauth2": [
        "settings:write"
      ]
    },
    {
      "userSession": []
    }
  ],
  "responses": {
    "200": {
      "description": "Mode enregistré",
      "content": {
        "application/json": {
          "schema": {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "equal",
                  "individual"
                ]
              }
            },
            "required": [
              "mode"
            ],
            "additionalProperties": false
          }
        }
      }
    },
    "default": {
      "description": "Erreur - enveloppe problem+json (RFC 9457)",
      "content": {
        "application/problem+json": {
          "schema": {
            "$ref": "#/components/schemas/Problem"
          }
        }
      }
    }
  }
}
```
