> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.awork.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.awork.com/_mcp/server.

# Creates an agent schedule.

POST https://api.awork.com/api/v1/agents/{agentId}/schedules
Content-Type: application/json

Creates a schedule for an agent after validating its cadence, timezone, and optional project or task context.Any authenticated user.

Reference: https://developers.awork.com/apiv1/agent-schedules/post-schedules-by-agent-id

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `agentId` (string, required) — The Custom Agent ID.

### Body (application/json)

This endpoint expects a CreateAgentScheduleRequestModel.

- `name` (string, required) — The schedule display name.
- `cronRule` (string, required) — The cron rule used for recurring execution.
- `prompt` (string, optional, nullable) — Optional custom instructions for the initial message. Omitted, null, or blank input clears custom instructions.
- `recurrenceInterval` (integer, optional, nullable) — The number of matching cron occurrences between scheduled runs.
- `timezone` (string, optional, nullable) — The timezone for the cron rule.
- `projectId` (string, optional, nullable) — The optional project context id.
- `taskId` (string, optional, nullable) — The optional task context id.
- `isEnabled` (boolean, optional, nullable) — Whether the schedule is enabled.

## Response

### 200

OK

- `name` (string, optional, nullable) — The schedule display name.
- `id` (string, optional) — The schedule id.
- `createdOn` (string, optional) — When the schedule was created.
- `agentId` (string, optional, nullable) — The agent id that is executed by this schedule.
- `type` (string, optional, nullable) — Runtime target type: personal-agent or custom-agent.
- `ownerUserId` (string, optional) — The user id whose context is used to execute the scheduled run.
- `prompt` (string, optional, nullable) — Optional custom instructions. An omitted or null prompt means no custom instructions.
- `cronRule` (string, optional, nullable) — The normalized cron rule used for recurring execution.
- `recurrenceInterval` (integer, optional) — The number of matching cron occurrences between scheduled runs.
- `timezone` (string, optional, nullable) — The timezone used to evaluate the cron rule.
- `projectId` (string, optional, nullable) — The optional project context id.
- `taskId` (string, optional, nullable) — The optional task context id.
- `isEnabled` (boolean, optional) — Whether this schedule is active.
- `needsAttention` (boolean, optional) — Whether the schedule needs user attention.
- `lastFailureReason` (string, optional, nullable) — The latest rejection reason.
- `consecutiveFailureCount` (integer, optional) — The number of consecutive failed scheduled executions.
- `lastAttemptOn` (string, optional, nullable) — The latest occurrence time.
- `lastSuccessfulRunOn` (string, optional, nullable) — The latest accepted occurrence time.

## Errors

### 400 Bad Request Error

Bad Request

- `code` (string, required) — The error code.
- `description` (string, required) — The description of the error.
- `link` (string, required) — The link to the API documentation page.
- `details` (list of string, optional, nullable) — A list of details describing the error.
- `validationErrors` (list of ValidationErrorResponse, optional, nullable) — If a validation error occurred, this contains the validation errors for each property.
- `traceId` (string, optional, nullable) — The request trace id for tracking the request.

### 401 Unauthorized Error

Unauthorized

- `code` (string, required) — The error code.
- `description` (string, required) — The description of the error.
- `link` (string, required) — The link to the API documentation page.
- `details` (list of string, optional, nullable) — A list of details describing the error.
- `validationErrors` (list of ValidationErrorResponse, optional, nullable) — If a validation error occurred, this contains the validation errors for each property.
- `traceId` (string, optional, nullable) — The request trace id for tracking the request.

### 404 Not Found Error

Not Found

- `code` (string, required) — The error code.
- `description` (string, required) — The description of the error.
- `link` (string, required) — The link to the API documentation page.
- `details` (list of string, optional, nullable) — A list of details describing the error.
- `validationErrors` (list of ValidationErrorResponse, optional, nullable) — If a validation error occurred, this contains the validation errors for each property.
- `traceId` (string, optional, nullable) — The request trace id for tracking the request.

## Types

### ValidationErrorResponse

The validation error response.

- `property` (string, optional, nullable) — The name of the property that failed validation.
- `message` (string, optional, nullable) — The reason why this property failed validation.

## Examples

**Request**

```json
{
  "name": "Weekly client status report",
  "cronRule": "0 9 * * 1"
}
```

**Response**

```json
{
  "name": "string",
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "createdOn": "2024-01-15T09:30:00Z",
  "agentId": "123e4567-e89b-12d3-a456-426614174000",
  "type": "string",
  "ownerUserId": "123e4567-e89b-12d3-a456-426614174000",
  "prompt": "string",
  "cronRule": "string",
  "recurrenceInterval": 1,
  "timezone": "string",
  "projectId": "123e4567-e89b-12d3-a456-426614174000",
  "taskId": "123e4567-e89b-12d3-a456-426614174000",
  "isEnabled": true,
  "needsAttention": true,
  "lastFailureReason": "string",
  "consecutiveFailureCount": 1,
  "lastAttemptOn": "2024-01-15T09:30:00Z",
  "lastSuccessfulRunOn": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.awork.com/api/v1/agents/agentId/schedules"

payload = {
    "name": "Weekly client status report",
    "cronRule": "0 9 * * 1"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.awork.com/api/v1/agents/agentId/schedules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"Weekly client status report","cronRule":"0 9 * * 1"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.awork.com/api/v1/agents/agentId/schedules"

	payload := strings.NewReader("{\n  \"name\": \"Weekly client status report\",\n  \"cronRule\": \"0 9 * * 1\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.awork.com/api/v1/agents/agentId/schedules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Weekly client status report\",\n  \"cronRule\": \"0 9 * * 1\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.awork.com/api/v1/agents/agentId/schedules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Weekly client status report\",\n  \"cronRule\": \"0 9 * * 1\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.awork.com/api/v1/agents/agentId/schedules', [
  'body' => '{
  "name": "Weekly client status report",
  "cronRule": "0 9 * * 1"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.awork.com/api/v1/agents/agentId/schedules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Weekly client status report\",\n  \"cronRule\": \"0 9 * * 1\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Weekly client status report",
  "cronRule": "0 9 * * 1"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.awork.com/api/v1/agents/agentId/schedules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```