> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/infra-controller/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/infra-controller/_mcp/server.

# Cancel a Task

POST https://nico-rest-api.nico.svc.cluster.local/v2/org/{org}/nico/task/{id}/cancel
Content-Type: application/json

Cancel a Task.

The same handler is also mounted at `/v2/org/{org}/nico/rack/task/{id}/cancel`
for backward compatibility; prefer this path for new clients.

Cancellation is best-effort and idempotent: tasks in non-terminal
states (`Pending`, `Running`, `Waiting`) are marked `Terminated`
and any underlying Temporal workflow is terminated. Cancelling an
already-`Terminated` task returns the same task without changes.
Tasks that have already finished (`Succeeded` or `Failed`) cannot
be cancelled.

Tasks are site-scoped; `siteId` must be the Site where the task was
created. Org must have an Infrastructure Provider entity. User must
have authorization role with `PROVIDER_ADMIN` suffix.

Reference: https://docs.nvidia.com/infra-controller/infra-controller/rest-api-reference/api-reference/task/cancel-task

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: NVIDIA Infra Controller REST API
  version: 1.0.0
paths:
  /v2/org/{org}/nico/task/{id}/cancel:
    post:
      operationId: cancel-task
      summary: Cancel a Task
      description: >-
        Cancel a Task.


        The same handler is also mounted at
        `/v2/org/{org}/nico/rack/task/{id}/cancel`

        for backward compatibility; prefer this path for new clients.


        Cancellation is best-effort and idempotent: tasks in non-terminal

        states (`Pending`, `Running`, `Waiting`) are marked `Terminated`

        and any underlying Temporal workflow is terminated. Cancelling an

        already-`Terminated` task returns the same task without changes.

        Tasks that have already finished (`Succeeded` or `Failed`) cannot

        be cancelled.


        Tasks are site-scoped; `siteId` must be the Site where the task was

        created. Org must have an Infrastructure Provider entity. User must

        have authorization role with `PROVIDER_ADMIN` suffix.
      tags:
        - subpackage_task
      parameters:
        - name: org
          in: path
          description: Name of the Org
          required: true
          schema:
            type: string
        - name: id
          in: path
          description: UUID of the Task
          required: true
          schema:
            type: string
            format: uuid
        - name: Authorization
          in: header
          description: >-
            ```

            export JWT_BEARER_TOKEN="<jwt-bearer-token>"


            # Example org name: "acme-inc

            export ORG_NAME=<org-name>


            # Use the JWT bearer token in your API request auth header:

            curl -v -X GET -H "Content-Type: application/json" -H
            "Authorization: Bearer $JWT_BEARER_TOKEN"
            https://nico-rest-api.nico.svc.cluster.local/v2/org/$ORG_NAME/nico/user/current

            ```
          required: true
          schema:
            type: string
      responses:
        '202':
          description: |-
            Accepted. The cancellation request was accepted and the Task's
            last known state is returned. Clients should `GET` the task to
            observe the final state, since cancellation is best-effort and
            the operation may still be terminating.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Task'
        '400':
          description: Error response when request data cannot be validated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NICoAPIError'
        '403':
          description: >-
            Error response when user is not authorized to call an endpoint or
            retrieve/modify objects
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NICoAPIError'
        '404':
          description: Error response when requested object is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NICoAPIError'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                siteId:
                  type: string
                  format: uuid
                  description: ID of the Site that owns the task (tasks are site-scoped).
              required:
                - siteId
servers:
  - url: https://nico-rest-api.nico.svc.cluster.local
    description: Kubernetes Cluster
components:
  schemas:
    TaskStatus:
      type: string
      enum:
        - Unknown
        - Pending
        - Waiting
        - Running
        - Succeeded
        - Failed
        - Terminated
      description: Current state of the task.
      title: TaskStatus
    TaskReportV1Version:
      type: string
      enum:
        - '1'
      description: Schema version of this report. Always `1` for `TaskReportV1`.
      title: TaskReportV1Version
    TaskReportV1Status:
      type: string
      enum:
        - pending
        - running
        - completed
        - failed
        - skipped
      description: >
        Per-stage and per-step execution status.


        - `pending`   — workflow has not yet reached this stage/step.

        - `running`   — execution is in progress.

        - `completed` — execution finished successfully.

        - `failed`    — execution finished with an error; see `error`.

        - `skipped`   — the rule lists this component type but the task targets
        no components of that type, so the workflow will not invoke it.
      title: TaskReportV1Status
    TaskReportV1Step:
      type: object
      properties:
        componentType:
          type: string
          description: >-
            Component class this step targets, e.g. `Compute`, `NVLSwitch`,
            `PowerShelf`.
        status:
          $ref: '#/components/schemas/TaskReportV1Status'
        totalComponents:
          type: integer
          description: >
            Count of components of `componentType` this step targets. Surfaced
            here because the task representation does not include the per-type
            component map.
        completedComponents:
          type: integer
          description: >
            Reserved for a future best-effort activity contract that reports
            per-component outcomes. Not written under the current fail-fast
            contract and omitted by the producer.
        failedComponents:
          type: integer
          description: Reserved (see `completedComponents`).
        startedAt:
          type: string
          format: date-time
          description: >-
            Set when the step leaves `pending`. `skipped` steps carry no
            timestamp.
        finishedAt:
          type: string
          format: date-time
          description: Set when the step reaches a terminal state.
        error:
          type: string
          description: Failure summary when `status == failed`. Truncated to 512 bytes.
      required:
        - componentType
        - status
      description: >
        Execution state of one rule sequence step. Pairs 1:1 with the rule's
        ordered steps within the containing stage and shares its index.
      title: TaskReportV1Step
    TaskReportV1Stage:
      type: object
      properties:
        number:
          type: integer
          description: 1-based rule stage number.
        status:
          $ref: '#/components/schemas/TaskReportV1Status'
        steps:
          type: array
          items:
            $ref: '#/components/schemas/TaskReportV1Step'
        startedAt:
          type: string
          format: date-time
          description: Set when the stage leaves `pending`.
        finishedAt:
          type: string
          format: date-time
          description: Set when the stage reaches a terminal state.
        error:
          type: string
          description: Failure summary when `status == failed`. Truncated to 512 bytes.
      required:
        - number
        - status
        - steps
      description: >
        Execution state of one rule stage. `number` is the canonical key for
        joining a stage record back to its rule entry.
      title: TaskReportV1Stage
    TaskReportV1:
      type: object
      properties:
        version:
          $ref: '#/components/schemas/TaskReportV1Version'
          description: Schema version of this report. Always `1` for `TaskReportV1`.
        stages:
          type: array
          items:
            $ref: '#/components/schemas/TaskReportV1Stage'
        error:
          type: string
          description: >
            Top-level failure summary: the message from the first stage that
            fails in this report. Not overwritten by subsequent failures, so it
            remains the canonical task-level error. Truncated to 512 bytes by
            the producer.
      required:
        - version
        - stages
      description: >
        Structured execution report (version 1) for a Flow-scheduled task.

        The document mirrors the structure of the operation rule that drives the
        workflow: each `Stage` corresponds to one rule stage and each `Step`
        within a stage corresponds to one rule sequence step at the same index.


        Clients pick the decoder by the `version` field; future report schemas
        will be exposed as `TaskReportV2` etc. and conveyed via a parallel
        response field, leaving v1 consumers untouched.
      title: TaskReportV1
    Task:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier of the task.
        status:
          $ref: '#/components/schemas/TaskStatus'
          description: Current state of the task.
        description:
          type: string
          description: Human-readable description provided when the task was created.
        message:
          type: string
          description: >-
            Optional status or error message describing the current state or
            result.
        ruleId:
          type:
            - string
            - 'null'
          format: uuid
          description: |-
            Operation Rule that Flow resolved for this task — either because
            the caller pinned one via `ruleId` on the originating request or
            because Flow's default rule resolution picked it. Null if Flow
            has not yet recorded a resolution.
        started:
          type: string
          format: date-time
          description: Timestamp when the task started execution.
        finished:
          type: string
          format: date-time
          description: Timestamp when the task finished (succeeded, failed or terminated).
        created:
          type: string
          format: date-time
          description: Timestamp when the task was created.
        updated:
          type: string
          format: date-time
          description: Timestamp when the task was last updated.
        report:
          $ref: '#/components/schemas/TaskReportV1'
          description: >
            Structured v1 execution report for the task. Populated on
            single-task `GET` and `cancel` responses, and on list responses only
            when `includeReport=true` is set. Omitted when the task has not yet
            produced a report (e.g. still queued) or when the caller did not opt
            in on list endpoints.


            A future schema revision will be exposed as a new `TaskReportV2`
            schema referenced from a parallel response field; v1 consumers are
            not disturbed by that bump.
      description: >-
        A task representing an asynchronous, site-scoped operation against rack,
        tray, or other site infrastructure.
      title: Task
    NiCoApiErrorSource:
      type: string
      enum:
        - nico
      description: Source of the error.
      title: NiCoApiErrorSource
    NiCoApiErrorData:
      type: object
      properties: {}
      description: Additional data about the error
      title: NiCoApiErrorData
    NICoAPIError:
      type: object
      properties:
        source:
          $ref: '#/components/schemas/NiCoApiErrorSource'
          description: Source of the error.
        message:
          type: string
          description: Message describing the error
        data:
          oneOf:
            - $ref: '#/components/schemas/NiCoApiErrorData'
            - type: 'null'
          description: Additional data about the error
      description: Describes the error response from NVIDIA Infra Controller REST API
      title: NICoAPIError
  securitySchemes:
    JWTBearerToken:
      type: http
      scheme: bearer
      description: >-
        ```

        export JWT_BEARER_TOKEN="<jwt-bearer-token>"


        # Example org name: "acme-inc

        export ORG_NAME=<org-name>


        # Use the JWT bearer token in your API request auth header:

        curl -v -X GET -H "Content-Type: application/json" -H "Authorization:
        Bearer $JWT_BEARER_TOKEN"
        https://nico-rest-api.nico.svc.cluster.local/v2/org/$ORG_NAME/nico/user/current

        ```

```

## Examples



**Request**

```json
{
  "siteId": "660e8400-e29b-41d4-a716-446655440000"
}
```

**Response**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "Terminated",
  "description": "Power on rack components",
  "message": "Cancelled by user"
}
```

**SDK Code**

```python example-1
import requests

url = "https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel"

payload = { "siteId": "660e8400-e29b-41d4-a716-446655440000" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript example-1
const url = 'https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"siteId":"660e8400-e29b-41d4-a716-446655440000"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go example-1
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel"

	payload := strings.NewReader("{\n  \"siteId\": \"660e8400-e29b-41d4-a716-446655440000\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby example-1
require 'uri'
require 'net/http'

url = URI("https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"siteId\": \"660e8400-e29b-41d4-a716-446655440000\"\n}"

response = http.request(request)
puts response.read_body
```

```java example-1
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"siteId\": \"660e8400-e29b-41d4-a716-446655440000\"\n}")
  .asString();
```

```php example-1
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel', [
  'body' => '{
  "siteId": "660e8400-e29b-41d4-a716-446655440000"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp example-1
using RestSharp;

var client = new RestClient("https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"siteId\": \"660e8400-e29b-41d4-a716-446655440000\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift example-1
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["siteId": "660e8400-e29b-41d4-a716-446655440000"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://nico-rest-api.nico.svc.cluster.local/v2/org/org/nico/task/id/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```