@extends('layouts.app') @section('title', 'API Documentation') @section('content')

API Documentation

POST /api/form-submit

Submit form data from external websites to FormHub. Each project requires a valid API key sent in the request header.

Endpoint
{{ url('/api/form-submit') }}
Required Headers
HeaderValueDescription
X-API-Keyfk_xxxxxxxx...Your project API key (required)
Content-Typeapplication/jsonFor JSON requests
Acceptapplication/jsonRecommended
Sample JSON Body
{
  "form_name": "Contact",
  "name": "John Doe",
  "email": "john@example.com",
  "phone": "+1234567890",
  "message": "Hello, I would like more information.",
  "company": "Acme Inc"
}
Form Fields
FieldTypeRequiredDescription
form_namestringNoForm identifier (default: "Contact", or "Chatbot" when source is chatbot)
form_typestringNoAlias for form_name
sourcestringNowebsite (default) or chatbot
external_idstringNoUnique chatbot conversation ID (deduplicates resubmits). Alias: conversation_id
namestringNoVisitor name (stored as visitor_name)
emailstringNoVisitor email
phonestringNoVisitor phone
submitted_urlstringNoPage URL where the form was submitted
utm_sourcestringNoMarketing source (e.g. google, facebook). Also parsed from submitted_url if present
utm_mediumstringNoMarketing medium (e.g. cpc, email)
utm_campaignstringNoCampaign name
custom fieldsmixedNoAny additional fields are stored in form_data

Alternative: pass api_key in the request body instead of the header. Hidden honeypot fields (honeypot, website_url_hp) must remain empty.

cURL Example
curl -X POST "{{ url('/api/form-submit') }}" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-API-Key: fk_your_api_key_here" \
  -d '{
    "form_name": "Contact",
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "+1234567890",
    "message": "Hello!"
  }'
HTML Form Example
<form action="{{ url('/api/form-submit') }}" method="POST">
  <input type="hidden" name="api_key" value="fk_your_api_key_here">
  <input type="text" name="form_name" value="Contact">
  <input type="text" name="name" placeholder="Name" required>
  <input type="email" name="email" placeholder="Email" required>
  <input type="tel" name="phone" placeholder="Phone">
  <textarea name="message" placeholder="Message"></textarea>
  <button type="submit">Send</button>
</form>
Success Response (201)
{
  "success": true,
  "message": "Form submitted successfully.",
  "data": {
    "id": 42,
    "form_name": "Contact",
    "status": "new",
    "is_duplicate": false,
    "submitted_at": "2026-07-30T12:00:00+00:00"
  }
}
Error Responses
CodeExample
401
{ "success": false, "message": "Invalid or inactive API key." }
422
{ "success": false, "message": "Validation failed.", "errors": { ... } }
429
{ "success": false, "message": "Too many requests. Please try again later." }
500
{ "success": false, "message": "Unable to process form submission." }
CMS

Connect enquiry forms from custom CMS or Laravel websites to FormHub. Leads appear in Submissions with source Website.

Setup in FormHub
  1. Create a Client and a Project for the website.
  2. On the project page, generate an API Key (or use API Keys).
  3. Optional: set notification email, auto-reply, and SMTP on the project.
Recommended approach

Send leads from your CMS server (PHP/Laravel controller), not from browser JavaScript. This keeps the API key in .env and avoids exposing it in HTML.

Custom Laravel integration

1. Environment — add to the CMS site .env:

FORMHUB_URL={{ url('/') }}
FORMHUB_API_KEY=fk_your_api_key_here

2. Config — config/formhub.php:

<?php

return [
    'url' => rtrim(env('FORMHUB_URL', '{{ url('/') }}'), '/'),
    'api_key' => env('FORMHUB_API_KEY'),
];

3. Service — app/Services/FormHubService.php:

<?php

namespace App\Services;

use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;

class FormHubService
{
    public function submit(array $payload): array
    {
        $response = Http::timeout(15)
            ->acceptJson()
            ->withHeaders(['X-API-Key' => config('formhub.api_key')])
            ->post(config('formhub.url') . '/api/form-submit', $payload);

        if ($response->failed()) {
            throw new RequestException($response);
        }

        return $response->json();
    }
}

4. Controller — validate the CMS form, then forward to FormHub:

public function store(Request $request, FormHubService $formHub)
{
    $validated = $request->validate([
        'name' => 'required|string|max:255',
        'email' => 'required|email|max:255',
        'phone' => 'nullable|string|max:50',
        'message' => 'nullable|string|max:5000',
        'honeypot' => 'nullable|max:0',
    ]);

    if ($request->filled('honeypot')) {
        abort(422, 'Spam detected.');
    }

    $formHub->submit([
        'form_name' => 'Contact',
        'name' => $validated['name'],
        'email' => $validated['email'],
        'phone' => $validated['phone'] ?? null,
        'message' => $validated['message'] ?? null,
        'submitted_url' => url()->previous(),
        // any extra CMS fields are stored in form_data:
        'city' => $request->input('city'),
    ]);

    return back()->with('success', 'Thank you! We will contact you soon.');
}

5. CMS form — post to your Laravel route (not FormHub directly):

<form method="POST" action="@{{ route('contact.store') }}">
  @@csrf
  <input type="text" name="honeypot" value="" style="display:none" tabindex="-1" autocomplete="off">
  <input type="text" name="name" required>
  <input type="email" name="email" required>
  <input type="tel" name="phone">
  <textarea name="message"></textarea>
  <button type="submit">Send</button>
</form>
Multiple forms on one website

Use the same API key and change form_name per form (e.g. Contact, Brochure, Site Visit). FormHub filters submissions by form name.

Field mapping
CMS fieldFormHub fieldNotes
NamenameAlso accepts full_name, fname + lname
EmailemailUsed for duplicate / repeated lead detection
PhonephoneAlso accepts mobile
Form typeform_namee.g. Contact, Enquiry
Page URLsubmitted_urlOptional but recommended
Custom fieldsany keyStored in form_data (city, budget, etc.)
After submit
Chatbot

Send chatbot leads to FormHub using the same POST /api/form-submit endpoint. Set source to chatbot so leads appear separately from website forms.

Sample JSON body
{
  "source": "chatbot",
  "form_name": "Chatbot",
  "external_id": "chat_abc123",
  "name": "John Doe",
  "email": "john@example.com",
  "phone": "9999999999",
  "message": "Interested in 3BHK. Wants a site visit.",
  "submitted_url": "https://yoursite.com/",
  "intent": "site_visit",
  "chat_transcript": "User: Hi... Bot: Please share your email..."
}
Laravel example
$formHub->submit([
    'source' => 'chatbot',
    'form_name' => 'Chatbot',
    'external_id' => $conversationId,
    'name' => $lead['name'],
    'email' => $lead['email'] ?? null,
    'phone' => $lead['phone'] ?? null,
    'message' => $lead['summary'] ?? null,
    'submitted_url' => $lead['page_url'] ?? null,
    'chat_transcript' => $lead['transcript'] ?? null,
]);
Notes
Notes
@endsection