AppMage

Scheduler

This endpoint group provides functionalities for managing scheduled tasks, allowing creation, update, deletion, and retrieval of tasks that run at specified intervals or times.

Endpoints

POST /api/rpc (Method: SchedulerRpc.create)

  • Description: Add a new scheduled task

  • Request Body:

    {
      "method": "SchedulerRpc.create",
      "params": {
        "taskConfig": {
          "name": "My Task",
          "description": "Optional description",
          "schedule": "0 0 * * *",
          "actionType": "event",
          "actionConfig": {
            "eventName": "taskExecuted",
            "eventData": { "param1": "value1" }
          },
          "context": {
            "userId": "user123",
            "subscriptionId": "sub123"
          },
          "category": "user",
          "tags": ["tag1", "tag2"],
          "enabled": true,
          "timeZone": "UTC"
        },
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskConfig Object Yes The configuration for the scheduled task. Includes name (string), description (string, optional), schedule (cron string or "once:YYYY-MM-DDTHH:MM:SSZ"), actionType (enum: "event", "rpc", "workflow", "aiMessage"), actionConfig (object, specific to actionType), context (object, optional, execution context for the task), category (enum: "system", "user", "campaign", "automation", default: "user"), tags (array of strings, optional), enabled (boolean, default: true), timeZone (string, optional).
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": "65b9e0f2f3a6a9b4c8e7d6c5"
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.create",
        "params": {
          "taskConfig": {
            "name": "Daily Report",
            "schedule": "0 0 * * *",
            "actionType": "event",
            "actionConfig": {
              "eventName": "generateDailyReport"
            }
          },
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.update)

  • Description: Update an existing scheduled task

  • Request Body:

    {
      "method": "SchedulerRpc.update",
      "params": {
        "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
        "updatedConfig": {
          "name": "Updated Daily Report",
          "schedule": "0 1 * * *"
        },
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskId String Yes The ID of the task to update.
    updatedConfig Object Yes The updated configuration for the scheduled task. Fields are the same as taskConfig in create, but all are optional for updates.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": true
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.update",
        "params": {
          "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
          "updatedConfig": {
            "name": "New Daily Report Name",
            "schedule": "0 1 * * *"
          },
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.delete)

  • Description: Delete a scheduled task by ID

  • Request Body:

    {
      "method": "SchedulerRpc.delete",
      "params": {
        "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskId String Yes The ID of the task to delete.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": true
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API-KEY" \
      -d '{
        "method": "SchedulerRpc.delete",
        "params": {
          "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.getData)

  • Description: Get a list of scheduled tasks

  • Request Body:

    {
      "method": "SchedulerRpc.getData",
      "params": {
        "page": 1,
        "pageSize": 10,
        "filter": {
          "category": "user"
        },
        "sort": {
          "name": 1
        },
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    page Number No The page number for pagination (1-indexed).
    pageSize Number No The number of tasks per page.
    filter Object No A MongoDB-style query object to filter tasks.
    sort Object No A MongoDB-style sort object to order tasks.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": {
        "data": [
          {
            "_id": "65b9e0f2f3a6a9b4c8e7d6c5",
            "name": "Daily Report",
            "schedule": "0 0 * * *",
            "actionType": "event",
            "actionConfig": {
              "eventName": "generateDailyReport"
            },
            "category": "user",
            "enabled": true,
            "nextRun": "2024-01-31T00:00:00.000Z",
            "lastRun": null
          }
        ],
        "totalCount": 1
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.getData",
        "params": {
          "page": 1,
          "pageSize": 5,
          "filter": {
            "category": "user"
          },
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.findById)

  • Description: Get a specific scheduled task by ID

  • Request Body:

    {
      "method": "SchedulerRpc.findById",
      "params": {
        "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskId String Yes The ID of the task to retrieve.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": {
        "_id": "65b9e0f2f3a6a9b4c8e7d6c5",
        "name": "Daily Report",
        "schedule": "0 0 * * *",
        "actionType": "event",
        "actionConfig": {
          "eventName": "generateDailyReport"
        },
        "category": "user",
        "enabled": true,
        "nextRun": "2024-01-31T00:00:00.000Z",
        "lastRun": null
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.findById",
        "params": {
          "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.enable)

  • Description: Enable a scheduled task by ID

  • Request Body:

    {
      "method": "SchedulerRpc.enable",
      "params": {
        "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskId String Yes The ID of the task to enable.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": true
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.enable",
        "params": {
          "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'

POST /api/rpc (Method: SchedulerRpc.disable)

  • Description: Disable a scheduled task by ID

  • Request Body:

    {
      "method": "SchedulerRpc.disable",
      "params": {
        "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
        "context": {
          "userId": "user123",
          "subscriptionId": "sub123",
          "serviceCode": "code",
          "projectId": "project456"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    taskId String Yes The ID of the task to disable.
    context Object No Additional context for the RPC call, such as userId, subscriptionId, serviceCode, projectId.
  • Response:

    {
      "success": true,
      "data": true
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "SchedulerRpc.disable",
        "params": {
          "taskId": "65b9e0f2f3a6a9b4c8e7d6c5",
          "context": {
            "subscriptionId": "myTenantId"
          }
        }
      }'