
Actor Task Copier
Pricing
Pay per usage
Go to Store

Actor Task Copier
Copies actor tasks between accounts from one actor to another.
0.0 (0)
Pricing
Pay per usage
1
Total users
3
Monthly users
1
Runs succeeded
>99%
Last modified
3 years ago
src/main.js
1import { Actor } from 'apify';2import { ApifyClient } from 'apify-client';3
4await Actor.init()5
6const {7 isDryRun,8 sourceActorId,9 sourceApiToken,10 targetActorId,11 targetApiToken,12} = await Actor.getInput();13
14if (isDryRun) console.log('This is a dry run!');15
16console.log(sourceApiToken);17
18const sourceClient = new ApifyClient({ token: sourceApiToken });19const targetClient = new ApifyClient({ token: targetApiToken });20
21const sourceActor = await sourceClient.actor(sourceActorId).get();22const sourceUser = await sourceClient.user().get();23const targetActor = await targetClient.actor(targetActorId).get();24const targetUser = await targetClient.user().get();25
26console.log(`Copying from ${sourceUser.username}/${sourceActor.name} to ${targetUser.username}/${targetActor.name}`);27
28const tasksToBeCopied = [];29
30let hasMore = true;31let offset = 0;32while (hasMore) {33 const response = await sourceClient.tasks().list({ limit: 100, offset });34
35 for (const task of response.items) {36 if (task.actId === sourceActorId) tasksToBeCopied.push(task);37 }38
39 hasMore = response.items.length > 0;40 offset += response.limit;41}42
43console.log('Tasks to be copied:')44console.log(tasksToBeCopied.map(task => `- ${sourceUser.username}/${task.name}`).join('\n'));45
46if (!isDryRun) {47 console.log('Copying tasks...');48 for (const { id: taskId } of tasksToBeCopied) {49 const task = await sourceClient.task(taskId).get();50 await targetClient.tasks().create({51 actId: targetActorId,52 name: task.name,53 options: task.options,54 input: task.input,55 });56 console.log(`${sourceUser.username}/${task.name} copied.`);57 }58}59
60console.log('Done.');61await Actor.exit();
.dockerignore
# configurations.idea
# crawlee and apify storage foldersapify_storagecrawlee_storagestorage
# installed filesnode_modules
# git folder.git
Dockerfile
# Specify the base Docker image. You can read more about# the available images at https://sdk.apify.com/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node:16
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --omit=dev --omit=optional \ && echo "Installed NPM packages:" \ && (npm list --omit=dev --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version \ && rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Run the image.CMD npm start --silent
INPUT_SCHEMA.json
{ "title": "Add two integers", "type": "object", "schemaVersion": 1, "description": "This actor will copy all the tasks of a source actor and source user under the target actor and target user.", "properties": { "sourceActorId": { "title": "Source Actor ID", "type": "string", "description": "ID of a source actor", "editor": "textfield" }, "sourceApiToken": { "title": "Source user API token", "type": "string", "description": "API token of a source user", "editor": "textfield", "isSecret": true }, "targetActorId": { "title": "Target Actor ID", "type": "string", "description": "ID of a target actor", "editor": "textfield" }, "targetApiToken": { "title": "Target user API token", "type": "string", "description": "API token of a target user", "editor": "textfield", "isSecret": true }, "isDryRun": { "title": "Dry run", "type": "boolean", "description": "If dry run is enabled then actor will only list the tasks to be copied." } }, "required": ["sourceActorId", "sourceApiToken", "targetActorId", "targetApiToken"]}
package.json
{ "name": "getting-started-node", "version": "0.0.1", "type": "module", "description": "This is an example of an Apify actor.", "dependencies": { "apify": "^3.1.0" }, "devDependencies": {}, "scripts": { "start": "node src/main.js", "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1" }, "author": "It's not you it's me", "license": "ISC"}