# IRPCScheduledJobsAdmin.AddScheduledJob

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Administration API](https://developer.m-files.com/APIs/gRPC-API/admin/index.md) > [Scheduled jobs](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScheduledJobsAdmin/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScheduledJobsAdmin/AddScheduledJob/

Badges: `Administration API / specialized` `admin` `session`

Adds a scheduled job to the server or to the vault, depending on the job type.

- **Service:** [Scheduled jobs](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScheduledJobsAdmin/index.md) `MFiles.IRPCScheduledJobsAdmin`
- **gRPC method:** `/MFiles.IRPCScheduledJobsAdmin/AddScheduledJob`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/add-scheduled-job`
- **Request:** [`AddScheduledJobRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScheduledJobsAdmin/AddScheduledJob/index.md#request)
- **Response:** [`AddScheduledJobResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScheduledJobsAdmin/AddScheduledJob/index.md#response)
- **Book and level:** Administration API, specialized
- **Kind:** admin
- **Session:** Required: the session ID from LogIn in the mfiles-session-id-bin metadata.
- **Idempotent:** no
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

- `scheduled_job.type` and the session decide where the job goes and which rights it needs
  (see the service overview): a server job needs a server-level session; archiving jobs need a
  session of their vault.
- The server assigns the ID; `scheduled_job.id` is ignored.
- Takes effect immediately: an enabled job runs on its schedule.

<a id="request"></a>

## Request: AddScheduledJobRequest

A structure that specifies the response type for the corresponding method.

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `scheduled_job` | [`ScheduledJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ScheduledJob/index.md) | The new job. `id` is ignored. |
| `scheduled_job.id` | `int32` | Job ID. |
| `scheduled_job.name` | `string` | Job name. |
| `scheduled_job.is_enabled` | `bool` | If true, the job is enabled (runs according to the specified schedule). |
| `scheduled_job.schedule` | `bytes` | The schedule of this job (a serialized Task object of Task Scheduler). |
| `scheduled_job.type` | [`JobType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.JobType/index.md) | Job type. Values: `JOB_TYPE_UNINITIALIZED` (0), `JOB_TYPE_BACKUP` (1), `JOB_TYPE_RESTORE` (2), `JOB_TYPE_COPY_VAULT` (3), `JOB_TYPE_VERIFY_VAULT` (4), `JOB_TYPE_ARCHIVE_OBJECTS` (5), `JOB_TYPE_ARCHIVE_OLD_VERSIONS` (6), `JOB_TYPE_RESTORE_FROM_ARCHIVE` (7), `JOB_TYPE_OPTIMIZE_VAULT` (8), `JOB_TYPE_RECALCULATE_PROPERTY` (9), `JOB_TYPE_MIGRATE_VAULT` (10), `JOB_TYPE_ENCRYPT_FILE_DATA` (11). |
| `scheduled_job.data` | [`JobDataUnion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.JobDataUnion/index.md) | The job details as a union. |
| `scheduled_job.data.backup` | [`BackupJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.BackupJob/index.md) (oneof data) | Backup job. |
| `scheduled_job.data.restore` | [`RestoreJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.RestoreJob/index.md) (oneof data) | Restore job. |
| `scheduled_job.data.copy_vault` | [`CopyVaultJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.CopyVaultJob/index.md) (oneof data) | Vault copying job. |
| `scheduled_job.data.verify_vault` | [`VerifyVaultJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.VerifyVaultJob/index.md) (oneof data) | Vault verifying job. |
| `scheduled_job.data.archive_objects` | [`ArchiveDocsJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ArchiveDocsJob/index.md) (oneof data) | Archiving documents job. |
| `scheduled_job.data.archive_old_versions` | [`ArchiveOldVersionsJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ArchiveOldVersionsJob/index.md) (oneof data) | Archiving old document versions job. |
| `scheduled_job.data.restore_from_archive` | [`RestoreFromArchiveJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.RestoreFromArchiveJob/index.md) (oneof data) | Restoring documents from archive job. |
| `scheduled_job.data.optimize_vault` | [`OptimizeVaultJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OptimizeVaultJob/index.md) (oneof data) | Optimize the vault. |
| `scheduled_job.data.recalculate_property` | [`RecalculateJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.RecalculateJob/index.md) (oneof data) | Recalculate a property. |
| `scheduled_job.data.migrate_vault` | [`MigrateVaultJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.MigrateVaultJob/index.md) (oneof data) | Vault migration job. |
| `scheduled_job.data.encrypt_file_data` | [`EncryptFileDataJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.EncryptFileDataJob/index.md) (oneof data) | Vault file data encryption job. |
| `scheduled_job.is_temporary` | `bool` | True if the job is temporary and thus executed only once. Temporary jobs are not scheduled so their run info should not be interpreted. |

<a id="response"></a>

## Response: AddScheduledJobResponse

A structure that specifies the response type for the corresponding method.

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `id` | `int32` | The ID of the new job. |
| `run_info` | [`ScheduledJobRunInfo`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ScheduledJobRunInfo/index.md) | The run state of the new job. |
| `run_info.is_running` | `bool` | True if the job is currently running. |
| `run_info.next_run_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The next time the job will run. Zero to indicate no next run time. |
| `run_info.last_run_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The last time the job ran. Zero to indicate that the job has never run (or is still running for the first time). |
| `run_info.last_run_succeeded` | `bool` | True if the last run at ftLastRun was successful, false otherwise. |
| `run_info.last_run_errors` | `string` | Error string from the last run (if any). |
| `run_info.last_run_cancelled` | `bool` | True if the job is cancelled. |
| `run_info.current_step` | `int32` | -1 or a current job step. 0 indicates the beginning. When positive, value depends on the underlying job that is being executed. Steps are numbered sequentially from 1 to forward. |
| `run_info.curent_step_completion` | `int32` | -1 or the completion percent of a current job. This is always an estimate. |
| `run_info.output` | [`ScheduledJobOutputInfo`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ScheduledJobOutputInfo/index.md) | The output information on the job. Available only when the job is not running (e.g. bRunning and is false). |
| `run_info.output.id` | `int32` | Job ID. |
| `run_info.output.message` | `string` | General output info message. |
| `run_info.output.type` | [`JobType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.JobType/index.md) | Job type. Values: `JOB_TYPE_UNINITIALIZED` (0), `JOB_TYPE_BACKUP` (1), `JOB_TYPE_RESTORE` (2), `JOB_TYPE_COPY_VAULT` (3), `JOB_TYPE_VERIFY_VAULT` (4), `JOB_TYPE_ARCHIVE_OBJECTS` (5), `JOB_TYPE_ARCHIVE_OLD_VERSIONS` (6), `JOB_TYPE_RESTORE_FROM_ARCHIVE` (7), `JOB_TYPE_OPTIMIZE_VAULT` (8), `JOB_TYPE_RECALCULATE_PROPERTY` (9), `JOB_TYPE_MIGRATE_VAULT` (10), `JOB_TYPE_ENCRYPT_FILE_DATA` (11). |
| `run_info.output.data` | [`JobOutputInfoDataUnion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.JobOutputInfoDataUnion/index.md) | The job output info details as a union. |
