Skip to main content

Endpoint

POST /api/complete-job

Description

Completes a job by submitting answers to clarifying questions and triggers provider search. This endpoint:
  1. Retrieves the job from in-memory storage using job_id
  2. Merges clarification answers into the job object
  3. Builds a search prompt from the complete job context
  4. Calls Grok Fast Search to find relevant service providers
  5. Saves providers to Supabase database with normalized data
  6. Returns the updated job object and list of matched providers

Request Body

job_id
string
required
The job ID returned from the /api/start-job endpoint.Example: "550e8400-e29b-41d4-a716-446655440000"
answers
object
required
Dictionary mapping question IDs to user’s answers. Keys should match the question id values from the start-job response.Example:
{
  "q1": "The toilet is constantly running",
  "q2": "Yes, water runs non-stop",
  "q3": "About 10 years old",
  "q4": "No water damage visible",
  "q5": "Not an emergency, can wait a day"
}

Response

job
object
The complete job object with all details and updated status.
providers
array
Array of matched service providers found via Grok Fast Search.

Example Request

curl -X POST http://localhost:8000/api/complete-job \
  -H "Content-Type: application/json" \
  -d '{
    "job_id": "550e8400-e29b-41d4-a716-446655440000",
    "answers": {
      "q1": "The toilet is constantly running",
      "q2": "Yes, water runs non-stop",
      "q3": "About 10 years old",
      "q4": "No water damage visible",
      "q5": "Not an emergency, can wait a day"
    }
  }'

Example Response

{
  "job": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "original_query": "fix my toilet",
    "task": "plumber",
    "house_address": "123 Main St, San Jose, CA 95126",
    "zip_code": "95126",
    "date_needed": "2025-12-10",
    "price_limit": 250,
    "clarifications": {
      "q1": "The toilet is constantly running",
      "q2": "Yes, water runs non-stop"
    },
    "questions": [
      {
        "id": "q1",
        "question": "What is the specific issue with your toilet?"
      },
      {
        "id": "q2",
        "question": "Is the toilet running constantly or leaking?"
      }
    ],
    "status": "searched"
  },
  "providers": [
    {
      "id": 1,
      "job_id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Reliable Plumbing Services",
      "phone": "(408) 555-0101",
      "estimated_price": 150.0,
      "negotiated_price": null,
      "call_status": "pending"
    },
    {
      "id": 2,
      "job_id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Bay Area Plumbers",
      "phone": "(408) 555-5678",
      "estimated_price": 200.0,
      "negotiated_price": null,
      "call_status": "pending"
    }
  ]
}

Error Responses

{
  "detail": "Job not found: 550e8400-e29b-41d4-a716-446655440000"
}
{
  "detail": "Error completing job: Grok Fast Search API unavailable"
}

Implementation Details

Provider Search Process

  1. Context Formatting: Answers are formatted into a natural paragraph for context
  2. Problem Statement: Grok LLM generates a formatted problem statement from the query and task
  3. Search Query: Complete job context (task, location, answers) is sent to Grok Fast Search
  4. Provider Normalization: Search results are parsed and normalized into provider records
  5. Database Storage: Each provider is saved to Supabase with:
    • Job ID and provider details (name, phone)
    • Context answers paragraph
    • Problem statement
    • Location data (address, ZIP)
    • Price constraints
    • Initial call status (“pending”)

Data Persistence

  • Job: Updated in-memory only (status changes to "searched")
  • Providers: Persisted to Supabase database for tracking throughout the negotiation process

Next Steps

After receiving providers, you can:
  1. Use POST /api/start-calls/ to initiate automated calls
  2. Poll GET /api/providers//status to track call progress and negotiated prices

Build docs developers (and LLMs) love