Webhooks
What are Webhooks?
Webhooks allow you to receive real-time notifications when your tasks are completed. Instead of repeatedly polling the API for task status, Pixwith.AI will automatically send a POST request to your specified URL when results are ready.
How to Configure
Step 1: Set Your Webhook URL
- Log in to your Pixwith.AI Dashboard
- Navigate to the API section
- Enter your webhook endpoint URL in the Webhook URL field
- Click Save
Step 2: Create Your Endpoint
const express = require('express');
const app = express();
app.use(express.json());
app.post('/webhook', (req, res) => {
const { code, message, data } = req.body;
const { task_id, task_type, status, result_urls } = data;
if (status === 2) {
// Task completed successfully
console.log('Task completed:', task_id);
console.log('Results:', result_urls);
} else if (status === 3) {
// Task failed
console.log('Task failed:', task_id);
}
res.status(200).send('OK');
});
app.listen(3000);Webhook Structure
When a task completes, Pixwith.AI sends a POST request with the following JSON payload:
Successful Task
{
"code": 1,
"message": "success",
"data": {
"task_id": "d425ab4dc256f0ebaa84862b9cea8a3d",
"task_type": "t2i",
"status": 2,
"result_urls": [
"https://cdn.pixwithapi.online/d425ab4dc256f0ebaa84862b9cea8a3d_0.png",
"https://cdn.pixwithapi.online/d425ab4dc256f0ebaa84862b9cea8a3d_1.png"
]
}
}Failed Task
{
"code": 1,
"message": "success",
"data": {
"task_id": "d425ab4dc256f0ebaa84862b9cea8a3d",
"task_type": "t2i",
"status": 3,
"result_urls": []
}
}Fields Description
| Field | Type | Description |
|---|---|---|
code | integer | Response code: 1 (success) |
message | string | Response message |
data.task_id | string | Unique identifier for the task |
data.task_type | string | Task type: t2i (text to image), i2i (image to image), t2v (text to video), i2v (image to video) |
data.status | integer | Task status: 2 (completed), 3 (failed) |
data.result_urls | array | Array of generated media URLs (empty when status is 3) |
Note: Your webhook endpoint must respond with a 200 OK status code within 5 seconds.
Last updated on