Skip to content

fix(task): support raw task IDs in task run - #1388

Open
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/task-run-raw-id-resolution
Open

fix(task): support raw task IDs in task run#1388
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/task-run-raw-id-resolution

Conversation

@kuntal1461

@kuntal1461 kuntal1461 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #1360

Problem

apify task run <rawId> fails with "Cannot find Task with name …" for any raw Apify task ID. The resolveTaskId method has only two branches:

  1. Input contains / → use as-is (username/task-name)
  2. Input has no /always prepend the authenticated username → username/rawId → 404

The argument description has always read "Name or ID of the Task to run (e.g. 'my-task' or 'E2jjCZBezvAZnX8Rb')". The ID half has never worked.

The identical bug was fixed for apify call in ffb0b7c3 (fix(call): support calling with bare ids) but was never applied to task run.

Fix

Import APIFY_ID_REGEX from @apify/consts (already in the dependency tree) and use it as a gate before the name-based fallback:

bare argument
  │
  ├─ contains "/" ──────────────────────→ client.task(id).get()  [unchanged]
  │
  └─ matches APIFY_ID_REGEX ──────────→ client.task(rawId).get()  [new]
       │                                      │
       │ not found                            └─ found → return task
       └─────────────────────────────────────→ client.task("username/name").get()  [existing]

Normal task names containing hyphens (e.g. my-task) do not match APIFY_ID_REGEX and skip the new path entirely — zero extra API calls for existing usage.

Changes

  • src/commands/task/run.ts — add APIFY_ID_REGEX import and raw-ID lookup path in resolveTaskId; update error message to "name or ID" (consistent with actors/call.ts:315)
  • test/api/commands/task/run.test.ts — capture rawTaskId = task.id in beforeAll; add 'should work with just the task ID' test case

Behaviour matrix

Input Before After API calls
yRWwqZmoMTLdEoMOI (raw ID) ❌ 404 ✅ resolves 1
my-task (bare name) 1 — unchanged
username/my-task (qualified) 1 — unchanged

Install size

No new package. APIFY_ID_REGEX is an additional named import from @apify/consts, which is already in the dependency tree.

Out of scope

task publish and task unpublish carry the same pattern but their documented contract lists names only — tracked separately.

Use APIFY_ID_REGEX from @apify/consts to detect a raw Apify resource ID
and attempt a direct client.task(id) lookup before falling back to the
existing username/name path. Normal task names skip the extra lookup.
git commit -F /tmp/commit_msg.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task run treats raw public task IDs as local task names

2 participants