# Create a job definition

**Operation ID:** `createJobDefinition`

Creates a job definition.

## Request

```http
POST https://{viya-host}/jobDefinitions/definitions
```

Replace `{viya-host}` with the hostname of your SAS Viya environment, for example `viya.example.com`.

## Parameters

### Query parameters

| Name | Required | Type | Description |
| --- | --- | --- | --- |
| `parentFolderUri` | no | string | The URI of the parent folder to contain the job definition. |

### Header parameters

| Name | Required | Type | Description |
| --- | --- | --- | --- |
| `accept` | no | string | Accept header value for the versioned media type corresponding to the version to be returned. |

## Request body

Optional.

### application/vnd.sas.job.definition+json

```json
{
  "title": "Job Definition Schema",
  "description": "The job definition.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The unique identifier for the job that is generated by the API."
    },
    "name": {
      "type": "string",
      "description": "The name of the job.",
      "maxLength": 255
    },
    "description": {
      "type": "string",
      "description": "The description of the job.",
      "maxLength": 1000
    },
    "type": {
      "type": "string",
      "description": "The type that determines which execution provider will run the job. Valid types include `Compute` (for SAS code), `casl` (for CASL scripts), and others installed on the deployment. The type must match an available execution provider, otherwise job execution will fail.",
      "maxLength": 250
    },
    "code": {
      "type": "string",
      "description": "Execution provider specific code to be executed."
    },
    "parameters": {
      "type": "array",
      "description": "An array of input parameters to be collected when executing this job definition",
      "items": {
        "$ref": "#/components/schemas/jobDefinitionParameter"
      }
    },
    "properties": {
      "type": "array",
      "description": "An array of name/value pairs needed to execute a job definition The maximum name length is 100.",
      "items": {
        "$ref": "#/components/schemas/resourceProperty"
      }
    },
    "creationTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was created, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "modifiedTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was last modified, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "createdBy": {
      "type": "string",
      "description": "The name of the user who created the job."
    },
    "modifiedBy": {
      "type": "string",
      "description": "The name of the last user who modified this object."
    },
    "links": {
      "type": "array",
      "description": "Links that apply to this object. Includes \"self\", \"alternate\", \"update\" and \"delete\".",
      "items": {
        "$ref": "#/components/schemas/link"
      }
    },
    "version": {
      "type": "integer",
      "description": "The version number of the representation. The current version is 2."
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

### application/json

```json
{
  "title": "Job Definition Schema",
  "description": "The job definition.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The unique identifier for the job that is generated by the API."
    },
    "name": {
      "type": "string",
      "description": "The name of the job.",
      "maxLength": 255
    },
    "description": {
      "type": "string",
      "description": "The description of the job.",
      "maxLength": 1000
    },
    "type": {
      "type": "string",
      "description": "The type that determines which execution provider will run the job. Valid types include `Compute` (for SAS code), `casl` (for CASL scripts), and others installed on the deployment. The type must match an available execution provider, otherwise job execution will fail.",
      "maxLength": 250
    },
    "code": {
      "type": "string",
      "description": "Execution provider specific code to be executed."
    },
    "parameters": {
      "type": "array",
      "description": "An array of input parameters to be collected when executing this job definition",
      "items": {
        "$ref": "#/components/schemas/jobDefinitionParameter"
      }
    },
    "properties": {
      "type": "array",
      "description": "An array of name/value pairs needed to execute a job definition The maximum name length is 100.",
      "items": {
        "$ref": "#/components/schemas/resourceProperty"
      }
    },
    "creationTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was created, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "modifiedTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was last modified, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "createdBy": {
      "type": "string",
      "description": "The name of the user who created the job."
    },
    "modifiedBy": {
      "type": "string",
      "description": "The name of the last user who modified this object."
    },
    "links": {
      "type": "array",
      "description": "Links that apply to this object. Includes \"self\", \"alternate\", \"update\" and \"delete\".",
      "items": {
        "$ref": "#/components/schemas/link"
      }
    },
    "version": {
      "type": "integer",
      "description": "The version number of the representation. The current version is 2."
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

## Responses

### 201 - The job definition was created.

**application/vnd.sas.job.definition+json**

```json
{
  "title": "Job Definition Schema",
  "description": "The job definition.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The unique identifier for the job that is generated by the API."
    },
    "name": {
      "type": "string",
      "description": "The name of the job.",
      "maxLength": 255
    },
    "description": {
      "type": "string",
      "description": "The description of the job.",
      "maxLength": 1000
    },
    "type": {
      "type": "string",
      "description": "The type that determines which execution provider will run the job. Valid types include `Compute` (for SAS code), `casl` (for CASL scripts), and others installed on the deployment. The type must match an available execution provider, otherwise job execution will fail.",
      "maxLength": 250
    },
    "code": {
      "type": "string",
      "description": "Execution provider specific code to be executed."
    },
    "parameters": {
      "type": "array",
      "description": "An array of input parameters to be collected when executing this job definition",
      "items": {
        "$ref": "#/components/schemas/jobDefinitionParameter"
      }
    },
    "properties": {
      "type": "array",
      "description": "An array of name/value pairs needed to execute a job definition The maximum name length is 100.",
      "items": {
        "$ref": "#/components/schemas/resourceProperty"
      }
    },
    "creationTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was created, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "modifiedTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was last modified, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "createdBy": {
      "type": "string",
      "description": "The name of the user who created the job."
    },
    "modifiedBy": {
      "type": "string",
      "description": "The name of the last user who modified this object."
    },
    "links": {
      "type": "array",
      "description": "Links that apply to this object. Includes \"self\", \"alternate\", \"update\" and \"delete\".",
      "items": {
        "$ref": "#/components/schemas/link"
      }
    },
    "version": {
      "type": "integer",
      "description": "The version number of the representation. The current version is 2."
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

**application/json**

```json
{
  "title": "Job Definition Schema",
  "description": "The job definition.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The unique identifier for the job that is generated by the API."
    },
    "name": {
      "type": "string",
      "description": "The name of the job.",
      "maxLength": 255
    },
    "description": {
      "type": "string",
      "description": "The description of the job.",
      "maxLength": 1000
    },
    "type": {
      "type": "string",
      "description": "The type that determines which execution provider will run the job. Valid types include `Compute` (for SAS code), `casl` (for CASL scripts), and others installed on the deployment. The type must match an available execution provider, otherwise job execution will fail.",
      "maxLength": 250
    },
    "code": {
      "type": "string",
      "description": "Execution provider specific code to be executed."
    },
    "parameters": {
      "type": "array",
      "description": "An array of input parameters to be collected when executing this job definition",
      "items": {
        "$ref": "#/components/schemas/jobDefinitionParameter"
      }
    },
    "properties": {
      "type": "array",
      "description": "An array of name/value pairs needed to execute a job definition The maximum name length is 100.",
      "items": {
        "$ref": "#/components/schemas/resourceProperty"
      }
    },
    "creationTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was created, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "modifiedTimeStamp": {
      "type": "string",
      "format": "date-time",
      "description": "The timestamp when the job was last modified, in the format of YYYY-MM-DDThh:mm:ss.sssZ."
    },
    "createdBy": {
      "type": "string",
      "description": "The name of the user who created the job."
    },
    "modifiedBy": {
      "type": "string",
      "description": "The name of the last user who modified this object."
    },
    "links": {
      "type": "array",
      "description": "Links that apply to this object. Includes \"self\", \"alternate\", \"update\" and \"delete\".",
      "items": {
        "$ref": "#/components/schemas/link"
      }
    },
    "version": {
      "type": "integer",
      "description": "The version number of the representation. The current version is 2."
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

### 400 - The request was invalid.

No response body.

### 415 - The requested media type is not supported.

No response body.

## Schemas

### jobDefinitionParameter

```json
{
  "title": "Job Definition Parameter Schema",
  "description": "Job definition parameter.",
  "properties": {
    "name": {
      "type": "string",
      "description": "The name of the parameter.",
      "maxLength": 100
    },
    "type": {
      "type": "string",
      "description": "The type of the parameter (TABLE, NUMERIC, DATE, CHARACTER).",
      "maxLength": 20
    },
    "label": {
      "type": "string",
      "description": "The display value for the name of this parameter.",
      "maxLength": 250
    },
    "required": {
      "type": "boolean",
      "description": "Specifies if the parameter is required for execution."
    },
    "defaultValue": {
      "type": "string",
      "description": "The default value for this parameter, if one is not specified at execution time."
    },
    "version": {
      "type": "integer",
      "description": "The version number of the representation. The current version is 1."
    }
  }
}
```

### resourceProperty

```json
{
  "title": "Resource Property Schema",
  "type": "object",
  "description": "A simple name value pair.",
  "properties": {
    "name": {
      "type": "string",
      "description": "The name."
    },
    "value": {
      "type": "string",
      "description": "The value."
    }
  }
}
```

### link

```json
{
  "title": "Link",
  "type": "object",
  "description": "A link to a related operation or resource.",
  "required": [
    "rel"
  ],
  "properties": {
    "method": {
      "type": "string",
      "description": "The HTTP method for the link."
    },
    "rel": {
      "type": "string",
      "description": "The relationship of the link to the resource."
    },
    "uri": {
      "type": "string",
      "description": "The relative URI for the link."
    },
    "href": {
      "type": "string",
      "description": "The URL for the link."
    },
    "title": {
      "type": "string",
      "description": "The title for the link."
    },
    "type": {
      "type": "string",
      "description": "The media type or link type for the link."
    },
    "itemType": {
      "type": "string",
      "description": "If this is a link to a container, `itemType` is the media type or link type for the items in the container."
    },
    "responseType": {
      "type": "string",
      "description": "The media type or link type of the response body for a `PUT`, `POST`, or `PATCH` operation."
    },
    "responseItemType": {
      "type": "string",
      "description": "The media type or link type of the items in the response body for a `PUT`, `POST`, or `PATCH` operation."
    }
  }
}
```

- [API index](/rest-apis/jobDefinitions-v4/index.md)
- [OpenAPI specification](/api/apis/jobDefinitions-v4/specifications/openapi.yml)
