Courses

Laravel HTTP Client and 3rd-Party APIs

Discord: POST to Channels via Webhooks

You're reading a FREE PREVIEW of a PREMIUM course.

Video Version of the Lesson

[Only for premium members]

Link to the repository

[Only for premium members]

Let's explore more complex HTTP Client usage by building a Discord webhook notification to alert your community when new tutorials are published.

We will send a message to the Discord server after submitting this long form:

Discord Notification Preview

This is the message we'll see on Discord:

Discord doesn't provide an official PHP package, unlike many APIs, so we must use the Laravel HTTP Client.


What You'll Learn

By the end of this lesson, you will learn how to:

  • Send POST requests with complex JSON structures and nested data
  • Retries: implement exponential backoff with jitter in cases when webhook doesn't work from the first attempt

Setting Up Your Discord Webhook

Discord webhooks are HTTP endpoints that allow external applications to send messages directly to Discord channels.

Before diving into code, you need a webhook URL from Discord:

  1. Navigate to your Discord server → Server Settings → Integrations
  2. Click "Create Webhook" or "View Webhooks"
  3. Choose your target channel and copy the webhook URL
  4. Optionally customize the webhook's name and avatar (we'll override these in code)

The webhook URL looks like: https://discord.com/api/webhooks/123456789/abcdefghijklmnop

This is the URL we would send our POST request to:

$webhookUrl = 'https://discord.com/api/webhooks/123456789/abcdefghijklmnop';
$payload = []; // we will later fill this array
Http::withHeaders(...)
->post($webhookUrl, $payload);

Critical note: Treat webhook URLs like...

The full lesson is only for Premium Members.
Want to access all 7 video+text lessons of this course? (50 min)

You also get:

  • 83 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord