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

# Cancel Session

PATCH https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/{session_id}/cancel

Forcefully cancel and close an active flow session, transition its status to `CLIENT_CANCELLED` (which can be monitored via [Get Session State](api:GET/es-public-administration/v1/manager/{session_id})), and prevent further customer interactions with the widget.

**Key Technical Details:**
- **No Request Body Required**: This operation does not accept a payload; it automatically defaults the cancellation reason to `CLIENT_CANCELLED` with empty feedback metadata.
- **Idempotency (304)**: If the session is already finalized (completed, failed, or cancelled), the endpoint transitions nothing and returns `304 Not Modified`.
- **Concurrency Lock (504)**: Acquires an exclusive database lock on the session. If the lock cannot be acquired within a reasonable time, it returns `504 Gateway Timeout`.

> This endpoint needs to be executed with an app secret, so should always be used in server side without exposing the secret to customers.


Reference: https://infonite.dev/api-reference/spain-public-administration/spain-public-administration-api/sessions-management/flows-es-public-administration-v-1-session-cancel

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: es-public-administration-v1-0-0-openapi
  version: 1.0.0
paths:
  /es-public-administration/v1/manager/{session_id}/cancel:
    patch:
      operationId: flows:es-public-administration:v1:session-cancel
      summary: Cancel Session
      description: >
        Forcefully cancel and close an active flow session, transition its
        status to `CLIENT_CANCELLED` (which can be monitored via [Get Session
        State](api:GET/es-public-administration/v1/manager/{session_id})), and
        prevent further customer interactions with the widget.


        **Key Technical Details:**

        - **No Request Body Required**: This operation does not accept a
        payload; it automatically defaults the cancellation reason to
        `CLIENT_CANCELLED` with empty feedback metadata.

        - **Idempotency (304)**: If the session is already finalized (completed,
        failed, or cancelled), the endpoint transitions nothing and returns `304
        Not Modified`.

        - **Concurrency Lock (504)**: Acquires an exclusive database lock on the
        session. If the lock cannot be acquired within a reasonable time, it
        returns `504 Gateway Timeout`.


        > This endpoint needs to be executed with an app secret, so should
        always be used in server side without exposing the secret to customers.
      tags:
        - sessionsManagement
      parameters:
        - name: session_id
          in: path
          description: Session ID to fetch
          required: true
          schema:
            type: string
            format: ObjectId
        - name: X-APP-SECRET
          in: header
          description: Application Secret
          required: true
          schema:
            type: string
      responses:
        '204':
          description: '**204 No Content**<br>Cancelled Successfully'
          content:
            application/json:
              schema:
                type: object
                properties: {}
        '404':
          description: '**404 Not Found**<br>Session not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: '**429 Too Many Requests**<br>Too many requests. Rate limit exceeded.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '504':
          description: '**504 Gateway Timeout**<br>Lock timeout, retry again'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
servers:
  - url: https://widgets.infonite.tech/api/flows
    description: Production Server
  - url: https://widgets-dev.infonite.tech/api/flows
    description: Development Server
  - url: /api/flows
    description: Local Server
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        detail:
          type: string
          description: Error message
      required:
        - detail
      description: Error response details
      title: ErrorResponse
    ValidationErrorLocItems:
      oneOf:
        - type: string
        - type: integer
      title: ValidationErrorLocItems
    ValidationErrorCtx:
      type: object
      properties: {}
      title: ValidationErrorCtx
    ValidationError:
      type: object
      properties:
        loc:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorLocItems'
        msg:
          type: string
        type:
          type: string
        input:
          description: Any type
        ctx:
          $ref: '#/components/schemas/ValidationErrorCtx'
      required:
        - loc
        - msg
        - type
      title: ValidationError
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
      title: HTTPValidationError
  securitySchemes:
    Application-Secret:
      type: apiKey
      in: header
      name: X-APP-SECRET
      description: Application Secret

```

## Examples



**SDK Code**

```python
import requests

url = "https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel"

headers = {"X-APP-SECRET": "<apiKey>"}

response = requests.patch(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel';
const options = {method: 'PATCH', headers: {'X-APP-SECRET': '<apiKey>'}};

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

```go
package main

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

func main() {

	url := "https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel"

	req, _ := http.NewRequest("PATCH", url, nil)

	req.Header.Add("X-APP-SECRET", "<apiKey>")

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

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

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

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel")

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

request = Net::HTTP::Patch.new(url)
request["X-APP-SECRET"] = '<apiKey>'

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel")
  .header("X-APP-SECRET", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel', [
  'headers' => [
    'X-APP-SECRET' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel");
var request = new RestRequest(Method.PATCH);
request.AddHeader("X-APP-SECRET", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["X-APP-SECRET": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://widgets.infonite.tech/api/flows/es-public-administration/v1/manager/session_id/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers

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()
```