Skip to Content
Endpoints

Shared Preconditions

How to work with shared preconditions using the public API

The shared preconditions endpoints allow you to manage reusable test preconditions that can be referenced across multiple test cases. Shared preconditions consist of a title and text content that describes the initial state or setup required before executing test cases.

About Shared Preconditions

Shared preconditions are reusable precondition templates that can be used in multiple test cases. They consist of:

  1. Title: A descriptive name for the shared precondition (required, minimum 1 character)
  2. Text: The actual precondition content in HTML format (required, minimum 1 character)

When a shared precondition is used in a test case, it provides consistent setup instructions. Updates to a shared precondition automatically propagate to all test cases that reference it.

  • Shared preconditions must have both a title and text content
  • The title of a shared precondition must be unique within a project
  • Shared preconditions are versioned - updates create new versions while preserving old ones
  • Deleted shared preconditions are no longer returned by these endpoints, but test case versions that reference them still return them, with deletedAt set

List Shared Preconditions

GET/api/public/v0/project/{project_id}/shared-precondition/paginated

/paginated endpoints are transitional. In API v1, the base paths will return paginated responses and the /paginated suffix will be removed.

Retrieves all shared preconditions within a project, optionally sorted and with additional fields included.

Path Parameters

  • project_id: The project identifier (can be either the project code or UUID)

Query Parameters

ParameterTypeDescriptionDefaultExample
offsetnumberNumber of items to skip.0offset=10
limitnumberMaximum number of items to return. Accepted range: 0–1,000.100limit=20
sortFieldstringField to sort by: created_at or title.titlesortField=title
sortOrderstringSort direction for sortField: asc or desc.ascsortOrder=asc
includestringInclude additional fields omitted by default. Accepted value: tcaseCount.Noneinclude=tcaseCount
  • Use include=tcaseCount to see how many test cases reference each shared precondition
  • Sorting by created_at shows the most recently created preconditions first (with desc) or oldest first (with asc)
  • Sorting by title provides alphabetical ordering
  • If no sortField is specified, the default sort is by title in ascending order

Example Request

Fetch all shared preconditions

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition/paginated

Fetch all shared preconditions sorted by title in ascending order

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition/paginated?sortField=title&sortOrder=asc"

Fetch all shared preconditions sorted by creation date (newest first)

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition/paginated?sortField=created_at&sortOrder=desc"

Fetch all shared preconditions with test case count included

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition/paginated?include=tcaseCount"

Response Fields

{
  total: number          // Number of matching shared preconditions across all pages
  offset: number         // Offset applied to this response
  limit: number          // Limit applied to this response
  data: Array<{          // Shared preconditions in this page
    projectId: string    //   ID of the project the precondition belongs to
    id: number           //   Shared precondition ID
    version: number      //   Version of the shared precondition
    title: string        //   Title of the shared precondition
    type: string         //   Type of the precondition (always `shared` for shared preconditions)
    text: html           //   Text of the precondition
    isLatest: boolean    //   Whether this is the latest version of the precondition
    createdAt: datetime  //   Time the shared precondition was first created
    updatedAt: datetime  //   Time this version was created
    tcaseCount?: number  //   Number of test cases using this shared precondition; only with `include=tcaseCount`
  }>
}

Example Response

{
  "total": 3,
  "offset": 0,
  "limit": 100,
  "data": [
    {
      "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
      "id": 1,
      "version": 2,
      "title": "User is logged in",
      "type": "shared",
      "text": "<p>The user has valid credentials and is authenticated in the system</p>",
      "isLatest": true,
      "createdAt": "2025-01-15T10:30:00.000Z",
      "updatedAt": "2025-01-20T14:45:00.000Z",
      "tcaseCount": 15
    },
    {
      "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
      "id": 2,
      "version": 1,
      "title": "Application is running",
      "type": "shared",
      "text": "<p>The application server is running and accessible</p>",
      "isLatest": true,
      "createdAt": "2025-01-16T09:15:00.000Z",
      "updatedAt": "2025-01-16T09:15:00.000Z",
      "tcaseCount": 15
    },
    {
      "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
      "id": 3,
      "version": 1,
      "title": "Database is initialized",
      "type": "shared",
      "text": "<p>The database contains the required test data</p>",
      "isLatest": true,
      "createdAt": "2025-01-17T11:20:00.000Z",
      "updatedAt": "2025-01-17T11:20:00.000Z",
      "tcaseCount": 3
    }
  ]
}

List Shared Preconditions (Deprecated)

Deprecated

This endpoint is deprecated. Use List Shared Preconditions (GET /api/public/v0/project/{project_id}/shared-precondition/paginated) instead.

GET/api/public/v0/project/{project_id}/shared-precondition

Retrieves all shared preconditions within a project, optionally sorted and with additional fields included.

Path Parameters

  • project_id: The project identifier (can be either the project code or UUID)

Query Parameters

All query parameters are optional.

ParameterTypeDescriptionDefaultExample
sortFieldstringField to sort by: created_at or title.titlesortField=title
sortOrderstringSort direction for sortField: asc or desc.ascsortOrder=asc
includestringInclude additional fields omitted by default. Accepted value: tcaseCount.Noneinclude=tcaseCount
  • Use include=tcaseCount to see how many test cases reference each shared precondition
  • Sorting by created_at shows the most recently created preconditions first (with desc) or oldest first (with asc)
  • Sorting by title provides alphabetical ordering
  • If no sortField is specified, the default sort is by title in ascending order

Example Request

Fetch all shared preconditions

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition

Fetch all shared preconditions sorted by title in ascending order

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition?sortField=title&sortOrder=asc"

Fetch all shared preconditions sorted by creation date (newest first)

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition?sortField=created_at&sortOrder=desc"

Fetch all shared preconditions with test case count included

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  "https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition?include=tcaseCount"

Response Fields

Array<{                // List of shared precondition objects
  projectId: string    // ID of the project the precondition belongs to
  id: number           // Shared precondition ID
  version: number      // Version of the shared precondition
  title: string        // Title of the shared precondition
  type: string         // Type of the precondition (always `shared` for shared preconditions)
  text: html           // Text of the precondition
  isLatest: boolean    // Whether this is the latest version of the precondition
  createdAt: datetime  // Time the shared precondition was first created
  updatedAt: datetime  // Time this version was created
  tcaseCount?: number  // Number of test cases using this shared precondition; only with `include=tcaseCount`
}>

Unlike the other deprecated lists, the array isn't wrapped in an object, and a project without shared preconditions returns null rather than [].

Example Response

[
  {
    "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
    "id": 1,
    "version": 2,
    "title": "User is logged in",
    "type": "shared",
    "text": "<p>The user has valid credentials and is authenticated in the system</p>",
    "isLatest": true,
    "createdAt": "2025-01-15T10:30:00.000Z",
    "updatedAt": "2025-01-20T14:45:00.000Z",
    "tcaseCount": 15
  },
  {
    "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
    "id": 2,
    "version": 1,
    "title": "Application is running",
    "type": "shared",
    "text": "<p>The application server is running and accessible</p>",
    "isLatest": true,
    "createdAt": "2025-01-16T09:15:00.000Z",
    "updatedAt": "2025-01-16T09:15:00.000Z",
    "tcaseCount": 15
  },
  {
    "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
    "id": 3,
    "version": 1,
    "title": "Database is initialized",
    "type": "shared",
    "text": "<p>The database contains the required test data</p>",
    "isLatest": true,
    "createdAt": "2025-01-17T11:20:00.000Z",
    "updatedAt": "2025-01-17T11:20:00.000Z",
    "tcaseCount": 3
  }
]

Get Shared Precondition

GET/api/public/v0/project/{project_id}/shared-precondition/{shared_precondition_id}

Get details of a single shared precondition using its ID.

Path Parameters

  • project_id: The project identifier (can be either the project code or UUID)
  • shared_precondition_id: The shared precondition identifier (numeric ID)

Example Request

curl \
  -H "Authorization: ApiKey your.api.key.here" \
  https://your-company.your-region-code.qasphere.com/api/public/v0/project/BD/shared-precondition/1

Response Fields

{
  projectId: string    // ID of the project the precondition belongs to
  id: number           // Shared precondition ID
  version: number      // Version of the shared precondition
  title: string        // Title of the shared precondition
  type: string         // Type of the precondition (always `shared` for shared preconditions)
  text: html           // Text of the precondition
  isLatest: boolean    // Whether this is the latest version of the precondition
  createdAt: datetime  // Time the shared precondition was first created
  updatedAt: datetime  // Time this version was created
  tcaseCount: number   // Number of test cases using this shared precondition
}

Example Response

{
  "projectId": "2HKj57k3z_YXYQVTdnPqrs8",
  "id": 1,
  "version": 2,
  "title": "User is logged in",
  "type": "shared",
  "text": "<p>The user has valid credentials and is authenticated in the system</p>",
  "isLatest": true,
  "createdAt": "2025-01-15T10:30:00.000Z",
  "updatedAt": "2025-01-20T14:45:00.000Z",
  "tcaseCount": 15
}

Create Shared Precondition

POST/api/public/v0/project/{project_id}/shared-precondition

Creates a shared precondition. Test cases use it by its ID, through precondition.sharedPreconditionId.

Request Body

{
  title: string  // Title (1–255 characters), unique in the project
  text: html     // Text of the precondition
}

Response

Status: 201 Created

The created shared precondition, as Get Shared Precondition returns it.

Errors

Status CodeDescription
409A shared precondition with the same title exists

Update Shared Precondition

PATCH/api/public/v0/project/{project_id}/shared-precondition/{shared_precondition_id}

Changes the title or the text of a shared precondition.

Every test case that uses the shared precondition gets a new version, and open runs get the new versions, like after any test case update.

Request Body

{
  title?: string  // New title (1–255 characters), unique in the project
  text?: html     // New text
}

Omitted fields are left unchanged. A request that changes nothing returns the shared precondition as it is, without a new version.

Response

Status: 200 OK

The updated shared precondition, as Get Shared Precondition returns it.

Errors

Status CodeDescription
409A shared precondition with the same title exists

Delete Shared Precondition

DELETE/api/public/v0/project/{project_id}/shared-precondition/{shared_precondition_id}

Deletes a shared precondition.

Irreversible

Deleted shared preconditions don't go to the trash and can't be restored. Every test case that uses the shared precondition gets a new version with its text copied in as a standalone precondition, so it can't be linked to the shared precondition again.

Response

Status: 200 OK

{
  message: string
}