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

# Update Testcase

> Replace the data of an existing Testcase while keeping its ID.



## OpenAPI

````yaml put /testcases/{testcaseId}
openapi: 3.1.0
info:
  title: Scorecard API
  description: REST API for Scorecard
  version: 1.0.0
servers:
  - url: https://api2.scorecard.io/api/v2
security:
  - ApiKeyAuth: []
paths:
  /testcases/{testcaseId}:
    put:
      summary: Update Testcase
      description: Replace the data of an existing Testcase while keeping its ID.
      operationId: updateTestcase
      parameters:
        - in: path
          name: testcaseId
          description: The ID of the Testcase to update.
          schema:
            type: string
            example: '248'
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                jsonData:
                  type: object
                  additionalProperties: true
                  description: >-
                    The JSON data of the Testcase, which is validated against
                    the Testset's schema.
              required:
                - jsonData
            examples:
              Update Testcase data:
                value:
                  jsonData:
                    question: What is the capital of France?
                    idealAnswer: Paris is the capital of France
                    provenance: hand_curated
                summary: Update Testcase data
                description: Update the content of a Testcase with improved information.
      responses:
        '200':
          description: Testcase updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Testcase'
              examples:
                Updated Testcase:
                  value:
                    id: '248'
                    testsetId: '246'
                    jsonData:
                      question: What is the capital of France?
                      idealAnswer: Paris is the capital of France
                      provenance: hand_curated
                    inputs:
                      question: What is the capital of France?
                    expected:
                      idealAnswer: Paris is the capital of France
                  summary: Updated Testcase
                  description: Example response showing a successfully updated Testcase.
        '401':
          $ref: '#/components/responses/UnauthenticatedError'
        '500':
          $ref: '#/components/responses/ServiceError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Scorecard from 'scorecard-ai';

            const client = new Scorecard({
              apiKey: 'My API Key',
            });

            const testcase = await client.testcases.update('248', {
              jsonData: {
                question: 'What is the capital of France?',
                idealAnswer: 'Paris is the capital of France',
                provenance: 'hand_curated',
              },
            });

            console.log(testcase.id);
        - lang: Python
          source: |-
            from scorecard_ai import Scorecard

            client = Scorecard(
                api_key="My API Key",
            )
            testcase = client.testcases.update(
                testcase_id="248",
                json_data={
                    "question": "What is the capital of France?",
                    "idealAnswer": "Paris is the capital of France",
                    "provenance": "hand_curated",
                },
            )
            print(testcase.id)
        - lang: cURL
          source: |-
            curl https://api2.scorecard.io/api/v2/testcases/$TESTCASE_ID \
                -X PUT \
                -H 'Content-Type: application/json' \
                -H "Authorization: Bearer $SCORECARD_API_KEY" \
                -d '{
                      "jsonData": {
                        "question": "bar",
                        "idealAnswer": "bar",
                        "provenance": "bar"
                      }
                    }'
components:
  schemas:
    Testcase:
      type: object
      properties:
        id:
          type: string
          description: The ID of the Testcase.
        testsetId:
          type: string
          description: The ID of the Testset this Testcase belongs to.
        jsonData:
          type: object
          additionalProperties: true
          description: >-
            The JSON data of the Testcase, which is validated against the
            Testset's schema.
        inputs:
          type: object
          additionalProperties: true
          description: >-
            Derived from data based on the Testset's fieldMapping. Contains all
            fields marked as inputs, including those with validation errors.
        expected:
          type: object
          additionalProperties: true
          description: >-
            Derived from data based on the Testset's fieldMapping. Contains all
            fields marked as expected outputs, including those with validation
            errors.
        validationErrors:
          type: array
          items:
            type: object
            properties:
              path:
                type: string
                description: JSON Pointer to the field with the validation error.
                example: /data/question
              message:
                type: string
                description: Human-readable error description.
                example: Required field missing
            required:
              - path
              - message
          description: >-
            Validation errors found in the Testcase data. If present, the
            Testcase doesn't fully conform to its Testset's schema.
      required:
        - id
        - testsetId
        - jsonData
        - inputs
        - expected
      description: >-
        A test case in the Scorecard system. Contains JSON data that is
        validated against the schema defined by its Testset.

        The `inputs` and `expected` fields are derived from the `data` field
        based on the Testset's `fieldMapping`, and include all mapped fields,
        including those with validation errors.

        Testcases are stored regardless of validation results, with any
        validation errors included in the `validationErrors` field.
    ApiError:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        details:
          type: object
          additionalProperties: true
          x-stainless-any: true
      required:
        - code
        - message
        - details
      description: An API error.
  responses:
    UnauthenticatedError:
      description: Error indicating that the request is not authenticated.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          examples:
            Authentication failure:
              value:
                code: UNAUTHORIZED
                message: Invalid or missing authentication token
                details: {}
              summary: Authentication failure
              description: >-
                Error returned when authentication credentials are invalid or
                missing.
    ServiceError:
      description: >-
        An internal service error indicating an issue with the Scorecard
        service.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          examples:
            Internal error:
              value:
                code: INTERNAL_ERROR
                message: An unexpected error occurred while processing your request.
                details: {}
              summary: Internal error
              description: Generic error when an unexpected internal issue occurs.
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: starts with ak_

````