📚 API Integration Guide

Ticket API Testing Guide

Setup

  1. Make sure your Laravel server is running: php artisan serve or php -S localhost:8000 -t public
  2. Ensure you have a tenant with an API token
  3. Update the test scripts with your actual tenant slug and API token

API Authentication

All tenant-specific endpoints require the X-Tenant-API-Token header with a valid API token.

Available Endpoints

Public Endpoints (No Authentication Required)

Create Tenant

curl -X POST http://localhost:8000/api/tenants \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Company",
    "description": "Company description",
    "address": "123 Main St",
    "phone": "+1234567890",
    "domain": "mycompany.com",
    "api_enabled": true
  }'

Response includes API token:

{
  "success": true,
  "data": {
    "id": 1,
    "name": "My Company",
    "api_token": "your-generated-api-token-here"
  }
}

Protected Endpoints (Require X-Tenant-API-Token Header)

Create a Ticket

curl -X POST http://localhost:8000/api/tickets \
  -H "Content-Type: application/json" \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN" \
  -d '{
    "title": "Login Issue",
    "description": "Cannot login to system",
    "priority": "high",
    "category_id": 1
  }'

Get All Tickets

curl -X GET http://localhost:8000/api/tickets \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN"

Get Specific Ticket

curl -X GET http://localhost:8000/api/tickets/1 \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN"

Update a Ticket

curl -X PUT http://localhost:8000/api/tickets/1 \
  -H "Content-Type: application/json" \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN" \
  -d '{
    "title": "Updated Title",
    "status": "in_progress"
  }'

Delete a Ticket

curl -X DELETE http://localhost:8000/api/tickets/1 \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN"

Get Tenant Information

curl -X GET http://localhost:8000/api/tenant \
  -H "X-Tenant-API-Token: YOUR_API_TOKEN"

Automated Testing

Using the Complete Test Script

chmod +x complete_api_test.sh
./complete_api_test.sh

This script will:

  1. Create a new tenant (and get its API token)
  2. Create a ticket using that token
  3. Retrieve all tickets for the tenant
  4. Show tenant information

Using the Artisan Command

php artisan test:ticket-api --tenant-slug=your-tenant --api-token=your-token

Expected Response Format

All responses follow this structure:

{
  "success": true|false,
  "message": "Response message",
  "data": { ... } | null
}

For validation errors:

{
  "success": false,
  "message": "Validation error",
  "errors": {
    "field_name": ["Error message"]
  }
}

Error Codes

  • 401: Invalid or missing API token
  • 403: API access disabled for tenant
  • 404: Resource not found
  • 422: Validation error
  • 500: Server error