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

# Update Shared Step

> Apply a partial update to a shared step collection. Uses optimistic concurrency control via expected_version.

<Info>
  **Permission Required**: `project:edit-tests`
</Info>

Apply a partial update to a shared step collection. Like
[Update Test](/api-reference/tests/update-test), this endpoint enforces an
optimistic version check via `expected_version`, returning `409` if the
collection has been modified since the version you fetched.

The `patch` field is deep-merged into the current collection. Arrays
(including `step_order`) are replaced wholesale.

## Path Parameters

<ParamField path="sharedStepId" type="string" required>
  The shared step collection ID
</ParamField>

## Request Body

<ParamField body="expected_version" type="integer" required>
  The version returned by the most recent
  [Get Shared Step](/api-reference/shared-steps/get-shared-step). Must be a
  non-negative integer.
</ParamField>

<ParamField body="patch" type="object" required>
  Partial collection body. Cannot change the collection `id` or `is_shared`.
</ParamField>

## Response

Returns the updated shared step (same shape as
[Get Shared Step](/api-reference/shared-steps/get-shared-step)) on success.

On version conflict, returns `409` with:

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "error": "version conflict",
  "expected_version": 1,
  "latest_version": 2
}
```

<RequestExample>
  ```bash cURL theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  curl -X PATCH "https://nunu.ai/api/v1/project/your-project-id/shared-steps/ssc_login" \
    -H "X-Api-Key: YOUR_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "expected_version": 2,
      "patch": { "name": "Login Flow v2" }
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  {
    "id": "ssc_login",
    "project_id": "test",
    "name": "Login Flow v2",
    "version": 3,
    "is_shared": true,
    "...": "..."
  }
  ```

  ```json 409 Conflict theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  {
    "error": "version conflict",
    "expected_version": 2,
    "latest_version": 3
  }
  ```
</ResponseExample>


## OpenAPI

````yaml PATCH /project/{projectId}/shared-steps/{sharedStepId}
openapi: 3.1.0
info:
  title: nunu.ai API
  description: >-
    The nunu.ai Public API allows you to programmatically interact with your
    projects, manage test runs, and upload builds.
  version: 1.0.0
servers:
  - url: https://nunu.ai/api/v1
security:
  - apiKeyAuth: []
paths:
  /project/{projectId}/shared-steps/{sharedStepId}:
    parameters:
      - name: projectId
        in: path
        required: true
        schema:
          type: string
        description: >-
          The project ID. You can copy it from the project settings page or the
          project URL in the dashboard.
    patch:
      tags:
        - Shared Steps
      summary: Update Shared Step
      description: >-
        Apply a partial update to a shared step collection. Uses optimistic
        concurrency control via expected_version.
      operationId: updateSharedStep
      parameters:
        - name: sharedStepId
          in: path
          required: true
          description: Shared step collection ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateSharedStepRequest'
      responses:
        '200':
          description: Shared step updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SharedStep'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden - missing project:edit-tests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Shared step not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Version conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VersionConflictError'
components:
  schemas:
    UpdateSharedStepRequest:
      type: object
      required:
        - expected_version
        - patch
      properties:
        expected_version:
          type: integer
          minimum: 0
        patch:
          type: object
          description: Partial collection body. Cannot change id or is_shared.
    SharedStep:
      type: object
      properties:
        id:
          type: string
        project_id:
          type: string
        name:
          type: string
        version:
          type: integer
        is_shared:
          type: boolean
        created_at:
          type: string
          format: date-time
          nullable: true
        created_by:
          type: string
          nullable: true
        steps_by_key:
          type: object
          additionalProperties: true
        step_order:
          type: array
          items:
            type: string
    Error:
      type: object
      properties:
        error:
          type: string
        code:
          type: string
        details:
          type: object
    VersionConflictError:
      type: object
      properties:
        error:
          type: string
          example: version conflict
        expected_version:
          type: integer
        latest_version:
          type: integer
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key
      description: API key for authentication

````