# Webhook Payload Reference

> Part of the [NextBlog documentation](https://nextblog.ai/docs.md). Live page: [https://nextblog.ai/docs/webhooks](https://nextblog.ai/docs/webhooks)

Webhooks allow you to receive real-time notifications when blog posts are approved or published. This enables you to integrate NextBlog with your custom applications and workflows.

**Looking for detailed webhooks integration guide?** See our [Webhooks Integration](/docs/integration-webhooks.md) page for step-by-step setup instructions, examples, and best practices.

### Setting Up Webhooks

To configure webhooks for your project:

1. Navigate to your project settings
2. Scroll to the "Webhooks" section
3. Enter your webhook URL (e.g., https://your-server.com/webhook)
4. Save your changes

### Webhook Events

Webhooks are triggered for the following events:

- **approved:** When a blog post is approved and published

### Webhook Payload

When a webhook is triggered, a POST request is sent to your webhook URL with the following payload:

```json
{
  "event": "approved",
  "timestamp": "2024-01-01T12:00:00Z",
  "blog": {
    "id": "blog_123",
    "title": "How to Optimize Your Website",
    "slug": "how-to-optimize-website",
    "description": "Learn the best practices...",
    "markdown": "# How to Optimize Your Website\n\n...",
    "cover_image_url": "https://example.com/image.jpg",
    "cover_image_alt": "Website optimization",
    "published": true,
    "status": "approved",
    "created_at": "2024-01-01T10:00:00Z",
    "updated_at": "2024-01-01T12:00:00Z",
    "project_id": "project_456"
  }
}
```

### Webhook Headers

Each webhook request includes the following headers:

```bash
Content-Type: application/json
User-Agent: NextBlog-Webhook/1.0
```

### Error Handling

If your webhook endpoint returns an error or is unreachable, NextBlog will automatically retry once. Failed webhooks are logged but do not prevent the blog post from being published.

### Security Best Practices

- Use HTTPS for your webhook URLs
- Validate the webhook payload on your server
- Implement rate limiting on your webhook endpoint
- Verify the event type before processing

### Example Webhook Handler

Here's an example webhook handler in Node.js:

```javascript
// Express.js webhook handler
app.post('/webhook', express.json(), (req, res) => {
  const { event, blog } = req.body;

  if (event === 'approved') {
    console.log('Blog post approved:', blog.title);
    // Process the approved blog post
    // e.g., sync to another CMS, send notifications, etc.
  }

  res.status(200).json({ received: true });
});
```
