AI Form Generation
Generate form fields using AI from a text description or by analyzing an existing webpage.
AI generation uses the same limits as your dashboard: 5/month on Free, unlimited on Pro+.
Endpoint
POST /api/v1/forms/generateScope required: forms:write
Description Mode
Generate a form from a natural language description.
cURL
curl -X POST "https://trigglio.com/api/v1/forms/generate" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "A customer feedback form for a SaaS product with name, email, satisfaction rating, and open-ended feedback",
"maxFields": 10
}'URL Analysis Mode
Analyze a webpage and generate a similar form.
{
"sourceUrl": "https://example.com/contact",
"maxFields": 20
}The API will fetch the page, extract form elements, and generate a matching form schema.
Response
{
"data": {
"suggestedName": "Customer Feedback Form",
"fields": [
{
"id": "field-1708...",
"type": "short_text",
"label": "Full Name",
"required": true,
"placeholder": "Jane Doe"
},
{
"id": "field-1708...",
"type": "email",
"label": "Email Address",
"required": true
},
{
"id": "field-1708...",
"type": "rating",
"label": "How satisfied are you with our product?",
"required": true,
"ratingConfig": {
"style": "stars",
"maxRating": 5,
"startLabel": "Very Unsatisfied",
"endLabel": "Very Satisfied"
}
}
],
"sourceAnalysis": null
}
}Generate and Create Workflow
The generation endpoint returns fields but does not save a form. To create a form from generated fields:
JavaScript
// Step 1: Generate fields
const genRes = await fetch('/api/v1/forms/generate', {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ description: 'Employee onboarding form' })
});
const { data: generated } = await genRes.json();
// Step 2: Create the form with generated fields
const createRes = await fetch('/api/v1/forms', {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
name: generated.suggestedName,
schema: {
fields: generated.fields,
settings: {
submitButtonText: 'Submit',
successMessage: 'Thank you!'
}
},
status: 'published'
})
});
const { data: form } = await createRes.json();
console.log(`Form created: ${form.id}`);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
description | string | One of description or sourceUrl required | Natural language description of the form |
sourceUrl | string | One of description or sourceUrl required | URL of a webpage to analyze |
maxFields | number | No | Maximum fields to generate (1-30, default: 25) |
Tips for Better Results
- Be specific: “Customer feedback form with name, email, 5-star rating, and comments” works better than “feedback form”
- Mention field types: “Include a dropdown for department selection” helps the AI choose the right field type
- Describe purpose: “Lead capture form for a real estate website” gives context for appropriate fields
- Set maxFields: For simple forms, use
maxFields: 5-8. For comprehensive ones, use15-25.
Error Codes
| Code | Status | Description |
|---|---|---|
validation_error | 400 | Missing or invalid input |
generation_failed | 400 | AI could not generate valid fields |
limit_exceeded | 403 | Monthly AI generation limit reached |
timeout | 408 | URL fetch timed out (15s limit) |
ai_rate_limited | 429 | AI service temporarily busy |
ai_service_unavailable | 503 | AI service not configured |
Last updated on