How to Integrate Lasso Moderation API in PHP (With Webhook Response)

Content moderation is critical for modern platforms that allow users to upload text, images, or videos. Lasso Moderation provides an API-based solution to automatically analyze and moderate content.

In this blog, we’ll cover:

  • What Lasso Moderation is
  • How to send content to Lasso using PHP
  • How webhooks work in Lasso
  • How to handle webhook responses in PHP/Laravel

What is Lasso Moderation?

Lasso Moderation is an AI-powered content moderation service that scans:

  • Text content
  • Images
  • Videos

Once content is submitted, Lasso processes it asynchronously and sends the moderation result back to your server using a webhook.

Flow Overview

  1. User creates content (post, image, video, etc.)
  2. Your backend sends content to Lasso API
  3. Lasso analyzes the content
  4. Lasso sends the moderation result to your webhook URL
  5. You update content status (approved / flagged / rejected)

Step 1: Prepare Content Payload in PHP

Below is an example payload structure you can send to Lasso.



$postData = [
    "content_id" => 1,
    "created_at" => "2025-01-11 12:11",
    "text" => "",
    "image_urls" => [
        "https://example.com/image.jpg"
    ],
    "video_urls" => [
        "https://example.com/video.mp4"
    ],
    "user" => [
        "id" => 2,
        "created_at" => "2025-01-11 12:11",
        "name" => "John",
        "email_domain" => "gmail",
        "email" => "john@gmail.com",
        "phone_number" => "9874563210"
    ],
    "category" => [
        "id" => "category_id",
        "name" => "Category Name"
    ],
    "subcategory" => [
        "id" => "subcategory_id",
        "name" => "Subcategory Name"
    ]
];

$postData = json_encode($postData);

Step 2: Send Data to Lasso API Using cURL

Use PHP cURL to send the content to Lasso’s moderation endpoint.

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => 'https://api.lassomoderation.com/api/v1/content',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $postData,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . getenv('LASSOKEY'),
    ],
]);

$response = curl_exec($curl);

if (curl_errno($curl)) {
    echo 'Curl Error: ' . curl_error($curl);
}

curl_close($curl);

echo $response;

# Notes

* Store your API key securely in `.env`

* The response usually confirms content submission, not final moderation

* Moderation result comes via webhook

Step 3: Configure Webhook in Lasso Dashboard

In your Lasso Dashboard:

1. Go to Webhooks

2. Add a webhook URL, for example:

```

https://yourdomain.com/lasso/webhook

```

3. Select events such as:

* Content Moderated

* Content Flagged

* Content Approved

Step 4: Handle Webhook Response (PHP / Laravel)

# Example Webhook Payload (Sample)

{
  "content_id": 1,
  "status": "flagged",
  "confidence_score": 0.92,
  "reasons": ["nudity", "violence"],
  "reviewed_at": "2025-01-11 12:15"
}

# Laravel Webhook Controller Example



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LassoWebhookController extends Controller
{
    public function handle(Request $request)
    {
        Log::info('Lasso Webhook Received', $request->all());

        $contentId = $request->content_id;
        $status    = $request->status;
        $reasons   = $request->reasons ?? [];

        // Example: update database
        /*
        Content::where('id', $contentId)->update([
            'moderation_status'  => $status,
            'moderation_reasons' => json_encode($reasons),
        ]);
        */

        return response()->json([
            'success' => true
        ]);
    }
}

# Webhook Route (Laravel)



use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LassoWebhookController;

Route::post('/lasso/webhook', [LassoWebhookController::class, 'handle']);

Step 5: Content Moderation Status Handling

Typical statuses you’ll receive:

Status Meaning
approved Content is safe
flagged Needs manual review
rejected Violates policy

Use this status to:

* Hide content automatically

* Send admin notifications

* Allow or block publishing

Best Practices

* Always verify webhook authenticity (signature / secret if provided by Lasso)

* Store raw webhook payload for audit

* Process webhooks asynchronously (queue jobs)

* Do not block user flow while waiting for moderation

Final Thoughts

Integrating Lasso Moderation with PHP is straightforward:

* Send content using REST API

* Receive results via webhook

* Automate moderation decisions in your app

This setup works perfectly with Laravel, core PHP, or microservices.