## Create Batch

`BatchCreateResponse Batches.Create(BatchCreateParamsparameters, CancellationTokencancellationToken = default)`

**post** `/api/v2/batches`

Create a batch over a source directory and start processing asynchronously.

### Parameters

- `BatchCreateParams parameters`

  - `required Config config`

    Body param: Batch configuration snapshot to apply to this source directory.

    - `required Job Job`

      Job to create for each file in the source directory.

      - `required string ConfigurationID`

        Product configuration ID or built-in preset ID matching the job type.

      - `required Type Type`

        Product job type to run for each source directory file.

        - `"parse_v2"ParseV2`

        - `"extract_v2"ExtractV2`

  - `required string sourceDirectoryID`

    Body param: Directory whose files should be processed.

  - `string? organizationID`

    Query param

  - `string? projectID`

    Query param

### Returns

- `class BatchCreateResponse:`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-PARSE_AGENTIC"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running.

  - `required string ID`

    Unique identifier

  - `required Config Config`

    Batch configuration snapshot.

    - `required Job Job`

      Job to create for each file in the source directory.

      - `required string ConfigurationID`

        Product configuration ID or built-in preset ID matching the job type.

      - `required Type Type`

        Product job type to run for each source directory file.

        - `"parse_v2"ParseV2`

        - `"extract_v2"ExtractV2`

  - `required string ProjectID`

    Project this batch belongs to.

  - `required string SourceDirectoryID`

    Directory being processed.

  - `required Status Status`

    Current batch status.

    - `"CANCELLED"Cancelled`

    - `"COMPLETED"Completed`

    - `"FAILED"Failed`

    - `"PENDING"Pending`

    - `"RUNNING"Running`

    - `"THROTTLED"Throttled`

  - `DateTimeOffset? CreatedAt`

    Creation datetime

  - `IReadOnlyList<Result>? Results`

    Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running.

    - `required string SourceDirectoryFileID`

      Source directory file processed by this batch.

    - `string? ErrorMessage`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `JobReference? JobReference`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `required string ID`

        Job ID, such as a parse job ID.

      - `required Type Type`

        Type of job produced for the file.

        - `"parse_v2"ParseV2`

        - `"extract_v2"ExtractV2`

  - `DateTimeOffset? UpdatedAt`

    Update datetime

### Example

```csharp
BatchCreateParams parameters = new()
{
    Config = new(
        new Job()
        {
            ConfigurationID = "cfg-PARSE_AGENTIC",
            Type = Type.ParseV2,
        }
    ),
    SourceDirectoryID = "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
};

var batch = await client.Batches.Create(parameters);

Console.WriteLine(batch);
```

#### Response

```json
{
  "id": "id",
  "config": {
    "job": {
      "configuration_id": "cfg-PARSE_AGENTIC",
      "type": "parse_v2"
    }
  },
  "project_id": "project_id",
  "source_directory_id": "source_directory_id",
  "status": "CANCELLED",
  "created_at": "2019-12-27T18:11:19.117Z",
  "results": [
    {
      "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "error_message": "error_message",
      "job_reference": {
        "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
        "type": "parse_v2"
      }
    }
  ],
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```
