Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 133 additions & 4 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1613,12 +1613,106 @@ These commands help you manage scheduled and configured Actor runs. Use them to

```sh
DESCRIPTION
Run saved Apify tasks (named Actor configurations). Only 'task run' is
available; create and manage tasks in Apify Console.
Manage and run saved Apify tasks (named Actor configurations with input and
options).

SUBCOMMANDS
task run Executes predefined Actor task remotely using local
key-value store for input.
task create Creates a new Actor task with optional saved input and
run options.
task info Prints information about a specific Actor task.
task ls Lists Actor tasks on your account.
task rm Permanently removes an Actor task from your account.
task run Executes predefined Actor task remotely using local
key-value store for input.
task update Updates an existing Actor task (title, description,
input, or run options).
```

##### `apify task create`

```sh
DESCRIPTION
Creates a new Actor task with optional saved input and run options.
Provide input via --input (inline JSON) or --input-file.

USAGE
$ apify task create <taskName> --actor <value>
[--build <value>] [--description <value>]
[-i <value> | -f <value>] [--json] [--memory <value>]
[--timeout <value>] [--title <value>]

ARGUMENTS
taskName Name for the new Task (unique under your account).

FLAGS
--actor=<value> Actor ID or name the task should
run (e.g. "apify/hello-world" or "my-actor").
--build=<value> Actor build tag or number to use
for the task (e.g. "latest" or "1.2.3").
--description=<value> Optional description for the
task.
-i, --input=<value> Saved task input as a JSON
string.
-f, --input-file=<value> Path to a JSON file with
saved task input.
--json Format the command output as
JSON.
--memory=<value> Memory limit for the task run,
in megabytes.
--timeout=<value> Timeout for the task run, in
seconds. Use 0 for no timeout.
--title=<value> Optional human-readable title
for the task.
```

##### `apify task info`

```sh
DESCRIPTION
Prints information about a specific Actor task.

USAGE
$ apify task info <taskId> [--json]

ARGUMENTS
taskId Name or ID of the Task (e.g. "my-task" or "username/my-task").

FLAGS
--json Format the command output as JSON.
```

##### `apify task ls`

```sh
DESCRIPTION
Lists Actor tasks on your account.

USAGE
$ apify task ls [--desc] [--json] [--limit <value>]
[--offset <value>]

FLAGS
--desc Sort tasks in descending order.
--json Format the command output as JSON.
--limit=<value> Number of tasks that will be listed.
--offset=<value> Number of tasks that will be skipped.
```

##### `apify task rm`

```sh
DESCRIPTION
Permanently removes an Actor task from your account.

USAGE
$ apify task rm <taskId> [-y]

ARGUMENTS
taskId Name or ID of the Task to delete.

FLAGS
-y, --yes Automatic yes to prompts; assume "yes" as answer to all
prompts.
```

##### `apify task run`
Expand All @@ -1645,6 +1739,41 @@ FLAGS
-t, --timeout=<value> Timeout for the Task run in seconds.
Zero value means there is no timeout.
```

##### `apify task update`

```sh
DESCRIPTION
Updates an existing Actor task (title, description, input, or run options).
Only the flags you pass are changed; omitted fields keep their current values.

USAGE
$ apify task update <taskId> [--build <value>]
[--description <value>] [-i <value> | -f <value>] [--json]
[--memory <value>] [--name <value>] [--timeout <value>]
[--title <value>]

ARGUMENTS
taskId Name or ID of the Task to update.

FLAGS
--build=<value> Actor build tag or number to use
for the task.
--description=<value> New description for the task.
-i, --input=<value> Replace saved task input
with this JSON string.
-f, --input-file=<value> Replace saved task input
with JSON from this file.
--json Format the command output as
JSON.
--memory=<value> Memory limit for the task run,
in megabytes.
--name=<value> New unique name for the task.
--timeout=<value> Timeout for the task run, in
seconds. Use 0 for no timeout.
--title=<value> New human-readable title for the
task.
```
<!-- task-commands-end -->
<!-- prettier-ignore-end -->

Expand Down
5 changes: 5 additions & 0 deletions scripts/generate-cli-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ const categories: Record<string, CommandsInCategory[]> = {
'task': [
//
{ command: Commands.task },
{ command: Commands.taskCreate },
{ command: Commands.taskInfo },
{ command: Commands.taskLs },
{ command: Commands.taskRm },
{ command: Commands.taskRun },
{ command: Commands.taskUpdate },
],
'mcp': [
//
Expand Down
16 changes: 14 additions & 2 deletions src/commands/task/_index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { TaskCreateCommand } from './create.js';
import { TaskInfoCommand } from './info.js';
import { TaskLsCommand } from './ls.js';
import { TaskRmCommand } from './rm.js';
import { TaskRunCommand } from './run.js';
import { TaskUpdateCommand } from './update.js';

export class TasksIndexCommand extends ApifyCommand<typeof TasksIndexCommand> {
static override name = 'task' as const;

static override description = `Run saved Apify tasks (named Actor configurations). Only 'task run' is available; create and manage tasks in Apify Console.`;
static override description = 'Manage and run saved Apify tasks (named Actor configurations with input and options).';

static override group = 'Apify Console';

static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-task';

static override subcommands = [TaskRunCommand];
static override subcommands = [
TaskCreateCommand,
TaskInfoCommand,
TaskLsCommand,
TaskRmCommand,
TaskRunCommand,
TaskUpdateCommand,
];

async run() {
this.printHelp();
Expand Down
141 changes: 141 additions & 0 deletions src/commands/task/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import process from 'node:process';

import type { ApifyApiError, Dictionary } from 'apify-client';
import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { Flags } from '../../lib/command-framework/flags.js';
import { resolveActorContext } from '../../lib/commands/resolve-actor-context.js';
import { getInputOverride } from '../../lib/commands/resolve-input.js';
import { error, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow, printJsonToStdout } from '../../lib/utils.js';

export class TaskCreateCommand extends ApifyCommand<typeof TaskCreateCommand> {
static override name = 'create' as const;

static override description =
'Creates a new Actor task with optional saved input and run options.\n' +
'Provide input via --input (inline JSON) or --input-file.';

static override examples = [
{
description: 'Create a task for an Actor with a name.',
command: 'apify task create my-task --actor apify/hello-world',
},
{
description: 'Create a task with saved JSON input and custom memory.',
command:
'apify task create my-task --actor my-username/my-actor --input \'{"url":"https://example.com"}\' --memory 2048',
},
{
description: 'Create a task using input from a file.',
command: 'apify task create my-task --actor my-actor --input-file ./input.json --title "Nightly scrape"',
},
];

static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-task-create';

static override args = {
taskName: Args.string({
required: true,
description: 'Name for the new Task (unique under your account).',
}),
};

static override flags = {
actor: Flags.string({
description: 'Actor ID or name the task should run (e.g. "apify/hello-world" or "my-actor").',
required: true,
}),
title: Flags.string({
description: 'Optional human-readable title for the task.',
}),
description: Flags.string({
description: 'Optional description for the task.',
}),
input: Flags.string({
char: 'i',
description: 'Saved task input as a JSON string.',
exclusive: ['input-file'],
}),
'input-file': Flags.string({
char: 'f',
description: 'Path to a JSON file with saved task input.',
exclusive: ['input'],
}),
Comment on lines +57 to +66

@l2ysho l2ysho Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here: siblings with these flags also declare the shorthands (src/commands/actors/call.ts:63,71):

		input: Flags.string({
			char: 'i',
			description: '...',
			exclusive: ['input-file'],
		}),
		'input-file': Flags.string({
			char: 'f',
			description: '...',
			exclusive: ['input'],
		}),

char is the only thing that registers a short alias (flags.ts:99-101 sets option.short), and parseArgs runs in strict: true mode, so without it -i is an unknown-option error. Right now docs/reference.md documents -i, --input for actors call but bare --input for task create — same flag, different ergonomics depending on namespace. Both chars are unclaimed here.

Same in task/update.ts:58-65.


Correction to my original version of this comment, which also asked for stdin: StdinMode.Stringified: that's wrong, it's already the default. flags.ts:118 is stdin: options.stdin ?? StdinMode.Stringified for the string builder, and the gate at apify-command.ts:572 is a truthiness check (rawFlag === '-' && builderData.stdin), so --input - already works as written. The explicit declarations in actors/call.ts are redundant. Only the char ask stands.

memory: Flags.integer({
description: 'Memory limit for the task run, in megabytes.',
}),
timeout: Flags.integer({
description: 'Timeout for the task run, in seconds. Use 0 for no timeout.',
}),
build: Flags.string({
description: 'Actor build tag or number to use for the task (e.g. "latest" or "1.2.3").',
}),
};

static override enableJsonFlag = true;

async run() {
const { taskName } = this.args;
const { actor: actorIdOrName, title, description, input, inputFile, memory, timeout, build, json } = this.flags;

const client = await getLoggedClientOrThrow();
const cwd = process.cwd();

const actorCtx = await resolveActorContext({ providedActorNameOrId: actorIdOrName, client });
if (!actorCtx.valid) {
error({
message: `${actorCtx.reason}. Please specify a valid Actor ID or name.`,
stdout: true,
});
process.exitCode ||= 1;
return;
}

const inputOverride = await getInputOverride(cwd, input, inputFile);
if (inputOverride === false) {
return;
}

const parsedInput = inputOverride?.input as Dictionary | undefined;

const options =
memory != null || timeout != null || build
? {
...(memory != null ? { memoryMbytes: memory } : {}),
...(timeout != null ? { timeoutSecs: timeout } : {}),
...(build ? { build } : {}),
}
: undefined;

try {
const newTask = await client.tasks().create({
actId: actorCtx.id,
name: taskName,
...(title ? { title } : {}),
...(description ? { description } : {}),
...(parsedInput !== undefined ? { input: parsedInput } : {}),
...(options ? { options } : {}),
});

if (json) {
printJsonToStdout(newTask);
return;
}

success({
message: `Task with ID ${chalk.yellow(newTask.id)} (called ${chalk.yellow(newTask.name)}) was created for Actor ${chalk.yellow(actorCtx.userFriendlyId)}.`,
stdout: true,
});
} catch (err) {
const casted = err as ApifyApiError;
error({
message: `Failed to create Task "${taskName}".\n ${casted.message || casted}`,
stdout: true,
});
process.exitCode ||= 1;
}
}
}
Loading