> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fieldiu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Agent

> Interact with the FieldIU AI Agent for bookings, work orders, and more

The AI Agent endpoints power FieldIU's intelligent automation layer. Use them to check appointment availability, confirm work orders, create incidents, and interact with the conversational AI.

***

## Confirm Work Order

<api-reference>POST /api/v1/ai-agent/confirm-workorder</api-reference>

Confirms or cancels a scheduled work order visit.

### Request Body

<ParamField body="wo_number" type="string">
  The work order number to confirm
</ParamField>

<ParamField body="confirmed" type="boolean">
  Set to `true` to confirm the visit, `false` to cancel
</ParamField>

<ParamField body="visit_date" type="string" required>
  The scheduled visit date and time (ISO 8601 format)
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/confirm-workorder \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{
      "wo_number": "WO-2024-001",
      "confirmed": true,
      "visit_date": "2024-06-15T09:00:00Z"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/confirm-workorder', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({
      wo_number: 'WO-2024-001',
      confirmed: true,
      visit_date: '2024-06-15T09:00:00Z'
    })
  });
  ```
</CodeGroup>

***

## Check Booking Availability

<api-reference>POST /api/v1/ai-agent/is-booking-available</api-reference>

Checks whether a specific date and time slot is available for booking.

### Request Body

<ParamField body="dateTime" type="string">
  The date and time to check, in ISO 8601 format (e.g. `2024-06-15T09:00:00Z`)
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/is-booking-available \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{ "dateTime": "2024-06-15T09:00:00Z" }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/is-booking-available', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({ dateTime: '2024-06-15T09:00:00Z' })
  });
  ```
</CodeGroup>

***

## Get Available Appointments

<api-reference>POST /api/v1/ai-agent/available-appointments</api-reference>

Returns a list of available appointment slots starting from a given date and time.

### Request Body

<ParamField body="dateTime" type="string">
  The starting date and time to search from, in ISO 8601 format
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/available-appointments \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{ "dateTime": "2024-06-15T00:00:00Z" }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/available-appointments', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({ dateTime: '2024-06-15T00:00:00Z' })
  });
  ```
</CodeGroup>

***

## Create Incident

<api-reference>POST /api/v1/ai-agent/create-incident</api-reference>

Logs a new pest or service incident linked to a client.

### Request Body

<ParamField body="clientName" type="string">
  Name of the client associated with the incident
</ParamField>

<ParamField body="insectName" type="string">
  Name or type of pest/insect involved in the incident
</ParamField>

<ParamField body="dateTime" type="string" required>
  Date and time of the incident in ISO 8601 format (e.g. `2017-07-21T17:32:28Z`)
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/create-incident \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{
      "clientName": "Acme Corporation",
      "insectName": "German Cockroach",
      "dateTime": "2024-06-10T14:30:00Z"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/create-incident', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({
      clientName: 'Acme Corporation',
      insectName: 'German Cockroach',
      dateTime: '2024-06-10T14:30:00Z'
    })
  });
  ```
</CodeGroup>

***

## Create Quote Request

<api-reference>POST /api/v1/ai-agent/create-quote-request</api-reference>

Submits a new quote request on behalf of a client.

### Request Body

<ParamField body="clientName" type="string" required>
  Name of the client requesting the quote
</ParamField>

<ParamField body="description" type="string" required>
  Description of the service or scope being quoted
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/create-quote-request \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{
      "clientName": "Acme Corporation",
      "description": "Monthly pest control service for a 3-floor commercial building"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/create-quote-request', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({
      clientName: 'Acme Corporation',
      description: 'Monthly pest control service for a 3-floor commercial building'
    })
  });
  ```
</CodeGroup>

***

## Get Work Order Details

<api-reference>POST /api/v1/ai-agent/get-wo-details</api-reference>

Retrieves full details for a specific work order by its number.

### Request Body

<ParamField body="woNumber" type="string" required>
  The work order number to look up
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/get-wo-details \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{ "woNumber": "WO-2024-001" }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/get-wo-details', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({ woNumber: 'WO-2024-001' })
  });
  ```
</CodeGroup>

***

## Ask the AI

<api-reference>POST /api/v1/ai-agent/ask</api-reference>

Sends a natural language query to the FieldIU AI assistant and returns a response. Supports multi-turn conversations via `chatId`.

### Request Body

<ParamField body="query" type="string" required>
  The natural language question or instruction to send to the AI
</ParamField>

<ParamField body="chatId" type="string" required>
  A UUID that groups messages into a single conversation thread. Generate a new UUID to start a fresh conversation
</ParamField>

<ParamField body="userId" type="string" required>
  The UUID of the user sending the query
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/ask \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id" \
    -d '{
      "query": "What are the open work orders for Acme Corporation?",
      "chatId": "550e8400-e29b-41d4-a716-446655440000",
      "userId": "660e8400-e29b-41d4-a716-446655440000"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/ask', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    },
    body: JSON.stringify({
      query: 'What are the open work orders for Acme Corporation?',
      chatId: '550e8400-e29b-41d4-a716-446655440000',
      userId: '660e8400-e29b-41d4-a716-446655440000'
    })
  });
  ```
</CodeGroup>

***

## Get Metadata

<api-reference>POST /api/v1/ai-agent/get-meta-data</api-reference>

Returns metadata and configuration available to the AI agent for your organization. No request body is required.

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://integration.fieldiu.online/api/v1/ai-agent/get-meta-data \
    -H "X-API-KEY: your_api_key" \
    -H "X-ORG-ID: your_org_id"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://integration.fieldiu.online/api/v1/ai-agent/get-meta-data', {
    method: 'POST',
    headers: {
      'X-API-KEY': 'your_api_key',
      'X-ORG-ID': 'your_org_id'
    }
  });
  ```
</CodeGroup>

### Response

`200 OK` — Returns organization metadata used by the AI agent.
