# Create a shell case (v2 - improved error handling)

Creates a shell case - an analysis case without uploaded files.
**Version 2 Improvements:**
This endpoint provides enhanced error handling with clear, actionable error messages:
- **Panel validation**: If specified panel names don't exist, returns a 400 error listing the invalid panel names
- **Assay validation**: If the assay ID is invalid or doesn't exist, returns a specific error message
- **Sample name validation**: If the sample name already exists, returns a clear duplicate error
- **Case name validation**: If the case name already exists, returns a clear duplicate error
- **Family relation validation**: For family cases, validates all family relations upfront
- **Assigned user validation**: If the `assigned_to` email does not belong to a user in the organization, returns a 400 error (unlike V1 which silently ignores invalid assignees)

Shell cases can be used to:
- Pre-register cases before files are available
- Set up case metadata in advance
- Later link files using the /v2/shell_case/link endpoint
- Implicitly link case files to samples based on file naming conventions (requires configuration by Franklin services)

**Common Error Responses:**
- `"Panel(s) not found: PanelX, PanelY"` - One or more specified virtual or hard panels don't exist
- `"Sample SampleName already exists"` - A sample with this name already exists
- `"Case CaseName already exists"` - A case with this name already exists
- `"Invalid assay id: not a valid UUID"` - The assay ID format is invalid
- `"Assay assay-id does not exist"` - The specified assay doesn't exist
- `"Invalid family relation(s): xyz. Valid relations are: proband, mother, father, ..."` - Invalid family relations specified
- `"Invalid assignedTo email: user@example.com"` - The assigned_to email does not belong to a user in the organization

Endpoint: POST /v2/shell_case/create
Version: 96
Security: bearerAuth

## Security:

  - `bearerAuth` (unknown)
    http bearer JWT

## Request fields (application/json):

  - `case_name` (string, required)
    Name for the shell case
    Example: Patient_001_Shell

  - `case_type` (string, required)
    Type of case
    Enum: "single", "family"

  - `samples_data` (array, required)
    Sample information

  - `samples_data.sample_name` (string, required)
    Sample name
    Example: Sample_001

  - `samples_data.patient_details` (object)
    Patient/subject details

  - `samples_data.patient_details.name` (string)
    Patient name
    Example: John Doe

  - `samples_data.patient_details.dob` (string)
    Date of birth (formats are dd-MM-yyyy, yyyy-MM-dd, dd/MM/yyyy)
    Example: 1990-05-15

  - `samples_data.patient_details.ethnicity` (string)
    Primary ethnicity (deprecated - use ethnicities)
    Example: European

  - `samples_data.patient_details.sex` (string)
    Biological sex
    Enum: "male", "female", "unknown"

  - `samples_data.patient_details.phenotypes` (array)
    HPO terms or phenotype descriptions
    Example: ["HP:0001250","Seizures"]

  - `samples_data.patient_details.major_phenotypes` (array)
    Subset of phenotypes considered major/primary. Must be a subset of phenotypes.
    Example: ["HP:0001250"]

  - `samples_data.patient_details.patient_id` (string)
    External patient identifier (e.g., MRN)
    Example: PAT-001

  - `samples_data.patient_details.ethnicities` (array)
    List of ethnic backgrounds
    Example: ["European","Ashkenazi Jewish"]

  - `samples_data.patient_details.description` (string)
    Clinical description
    Example: History of epilepsy

  - `samples_data.patient_details.cancer_type` (string)
    Cancer type (for oncology)
    Example: Breast Cancer

  - `samples_data.family_relation` (string)
    Family relation (for family cases)
    Example: proband

  - `samples_data.description` (string)
    Sample description
    Example: Primary sample

  - `samples_data.hard_panels` (array)
    Hard panel names
    Example: []

  - `samples_data.hard_panel_single_genes` (array)
    Individual genes for hard filter
    Example: []

  - `samples_data.sample_files_location` (object)
    Location configuration for sample files. Specifies where to fetch sample files from.
**Location Types:**
- `AWS` or `S3`: Files are fetched from AWS S3. Requires organization to have `caseFilesRootFolder` configured.
The final S3 path is constructed as: `{caseFilesRootFolder}/{folder_name}/`
where `folder_name` is either `s3_sample_files_folder_name_override` (if provided) or the sample name.
- `BASESPACE`: Files are fetched from Illumina BaseSpace. Requires `basespace_project` and `basespace_sample`.
If `basespace_rna_sample` is also provided, creates a tumor sample with RNA data.

  - `samples_data.sample_files_location.location` (string, required)
    The storage location type. Case insensitive.
- `AWS` or `S3`: Amazon S3 storage
- `BASESPACE`: Illumina BaseSpace
    Enum: "AWS", "S3", "BASESPACE"

  - `samples_data.sample_files_location.basespace_project` (string)
    BaseSpace project ID. Required when location is `BASESPACE`.
    Example: project-123

  - `samples_data.sample_files_location.basespace_sample` (string)
    BaseSpace biosample ID. Required when location is `BASESPACE`.
    Example: sample-456

  - `samples_data.sample_files_location.basespace_rna_sample` (string)
    BaseSpace RNA biosample ID. Optional for `BASESPACE` location.
When provided, creates a tumor sample with associated RNA data.
    Example: rna-sample-789

  - `samples_data.sample_files_location.s3_sample_files_folder_name_override` (string)
    Override the folder name used in the S3 path. Only applicable when location is `AWS` or `S3` and implicit linking is configured.
If not provided, the sample name is used as the folder name, following the root case files folder configured by Franklin PS.
Special characters are URL-encoded. Trailing slashes are stripped.
    Example: custom_folder_name

  - `samples_data.create_analysis` (boolean)
    Whether to create analysis record

  - `samples_data.affected` (boolean)
    Whether affected (for family)
    Example: true

  - `samples_data.sample_name_in_multi_sample_vcf` (string)
    Name in multi-sample VCF
    Example: SAMPLE001

  - `samples_data.consanguinity` (boolean)
    Whether there is known consanguinity in the family
    Example: false

  - `samples_data.include_secondary_findings` (boolean)
    Whether to include secondary findings for this sample.
Priority hierarchy (highest to lowest):
1. This sample-level setting
2. Case-level `include_secondary_findings` in the request
3. Organization's default setting
For family cases, the family analysis uses: case-level setting,
then proband's sample-level setting, then org default.
    Example: true

  - `assay_id` (string)
    Assay UUID
    Example: assay-uuid-123

  - `batch_name` (string)
    Batch name
    Example: Batch_2024_01

  - `virtual_panels` (array)
    Virtual panel names
    Example: ["Epilepsy Panel"]

  - `labels` (array)
    Labels to apply
    Example: ["pending_files"]

  - `extra_case_details` (object)
    Custom fields
    Example: {"referring_physician":"Dr. Smith"}

  - `assigned_to` (string)
    Email of user to assign to. V1 silently ignores invalid emails; V2 fails with an error if the user does not exist in the organization.
    Example: analyst@example.com

  - `case_order_name` (string)
    Case group name
    Example: Order_2024_001

  - `case_group_name` (string)
    Case group name
    Example: Group_2024_001

  - `protocols` (array)
    Analysis protocols
    Example: []

  - `include_secondary_findings` (boolean)
    Whether to include secondary findings for this case.
This is the case-level default that can be overridden per-sample.
If not specified, falls back to the organization's default setting.
    Example: true

## Response 200:

  - `200` (unknown)
    Shell case created successfully

## Response 200 fields (application/json):

  - `analysis_id` (integer, required)
    ID of created analysis
    Example: 12345

  - `analysis_name` (string, required)
    Name of created analysis
    Example: Patient_001_Analysis

## Response 400:

  - `400` (unknown)
    Bad request - invalid parameters. Common causes:
- Invalid panel names (panels don't exist)
- Invalid assay ID (not a UUID or doesn't exist)
- Duplicate sample or case name
- Invalid family relations

## Response 400 fields (application/json):

  - `error` (string, required)
    Error type
    Example: Not Found

  - `message` (string, required)
    Human-readable error description
    Example: Analysis with ID 12345 was not found

## Response 401:

  - `401` (unknown)
    Authentication failed - invalid or missing token

## Response 401 fields (application/json):

  - `error` (string, required)
    Error type
    Example: Not Found

  - `message` (string, required)
    Human-readable error description
    Example: Analysis with ID 12345 was not found

## Response 429:

  - `429` (unknown)
    Rate limit exceeded

## Response 429 fields (application/json):

  - `error` (string, required)
    Error type
    Example: Not Found

  - `message` (string, required)
    Human-readable error description
    Example: Analysis with ID 12345 was not found

## Response 429 headers (application/json):

  - `Retry-After` (integer)
    Number of seconds to wait before retrying

## Response 400 examples:

  - `Panel not found` (unknown)

  - `Invalid assay` (unknown)

  - `Duplicate sample` (unknown)

  - `Invalid family relation` (unknown)

  - `Invalid assigned_to email` (unknown)

