SetStages

[POST] .../v1/pipeline/setstages

Upserts CRM pipeline stages. Use this workflow method to replace the stage definition for a pipeline after Pipeline/Get has returned the current stage ids. The method validates every stage, updates stages with id, inserts stages without id, deletes omitted stages only when they are not used by Lead, Deal or stage-history rows, writes a stage action log record, invalidates the CRM pipeline cache and returns row_affected with the pipeline id. The request body is required, pipeline_id must be positive, stages must be non-empty, each stage must have a non-blank name limited to 200 characters and code is limited to 100 characters; Lead pipelines must keep active system stages with codes new, won and lost, while non-Lead pipelines must keep exactly one start stage and at least one terminal stage. The caller must have CRM pipeline edit permission; missing body, invalid pipeline_id or stages, duplicate stage names, invalid Lead system-stage code or activity, denied access, missing pipeline, database failures, transaction failures and action-log errors are returned as HTTP 200 ErrorResult business errors.

Request Parameters

Name Type Required Description
pipeline_id Int64 Required Pipeline ID.
stages Array of PipelineSetStage Required Stages to upsert.

Request Example

{
  "pipeline_id": 7,
  "stages": [
    {
      "id": 25,
      "name": "New",
      "code": "new",
      "sort_order": 10,
      "is_start": true,
      "is_terminal": false,
      "is_success": false,
      "active": true
    },
    {
      "id": 26,
      "name": "Qualification",
      "code": "qualification",
      "sort_order": 30,
      "is_start": false,
      "is_terminal": false,
      "is_success": false,
      "active": true
    },
    {
      "id": 27,
      "name": "Won",
      "code": "won",
      "sort_order": 90,
      "is_start": false,
      "is_terminal": true,
      "is_success": true,
      "active": true
    },
    {
      "id": 28,
      "name": "Lost",
      "code": "lost",
      "sort_order": 100,
      "is_start": false,
      "is_terminal": true,
      "is_success": false,
      "active": true
    }
  ]
}

Response Parameters

Name Type Description
ok Boolean Indicates whether the request completed successfully.
result Update Update operation result.

Response Example

{
  "ok": true,
  "result": {
    "row_affected": 1,
    "ids": [
      7
    ]
  }
}