This quickstart applies to one-off tasks and recurring cron and rrule schedules.

1. Define your task

Your task definition is where you'll perform your tasks, such as sending emails, processing files, or moving data between systems.

With Mergent, tasks are defined by HTTP request handlers inside your application.

routes/web.php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;

Route::post('/api/tasks', function (Request $request) {
    $body = $request->getContent();

    try {
        perform_task($body);
    } catch (Exception $e) {
        Log::error("Failed to perform task: {$e->getMessage()}");
        return response('', 500);
    }

    return response('', 200);
});

function perform_task($body) {
    // This is where you'll perform your task.
    // For now, we'll just log it.
    Log::info("Performing task: {$body}");
}

For a list of all the available parameters, visit the API Reference.

2. Get your handler's URL

Before you can run your task, your handler must be accessible from the internet.

To do this, you can use a tool like ngrok, or deploy your application to a platform like Vercel or Render.

For more information, see our guide to localhost dev & webhooks.

3. Create your first task

Once your task handler is reachable via a URL, you can create your first task. Go to the Mergent Tasks Dashboard and click the Create button.

In this step, you'll set the Request URL to your task handler's URL. You'll also provide the required parameters (in the request body) for your handler to carry out the task.

Typically, developers use a type parameter to distinguish between different tasks. This allows your task handler to route and process tasks accordingly. Feel free to structure your parameters in a way that works best for your application.

Click Create to queue the task. Once the task executes, you should see the related log in your console, indicating a successful run. 🎊

4. Next Steps

At this point, you have a few options:

Learn More