adv-web-scraper-api

AI API Documentation

This document details the API endpoints related to AI features.

Generate or Refine Scraping Configuration

Generates a new web scraping configuration based on a target URL and a natural language prompt, OR refines a previously generated configuration using user feedback. This process is asynchronous, and the status should be tracked using the Jobs API.

Request Body

{
  "url": "string",
  "prompt": "string",
  "previousJobId": "string (optional)",
  "fetchHtmlForRefinement": "boolean (optional, default: false)",
  "options": {
    "maxIterations": "number (optional, default: 3)",
    "testConfig": "boolean (optional, default: true)",
    "model": "string (optional, default: defined by environment)",
    "maxTokens": "number (optional, default: 8192)",
    "temperature": "number (optional, default: 0.7)",
    "browserOptions": {
      "headless": "boolean (optional, default: true)",
      "proxy": "boolean (optional, default: false)"
    },
    "interactionHints": ["string"] // Optional array of strings
  }
}

Parameters:

Success Response (202 Accepted)

Indicates that the generation or refinement job has been successfully queued.

{
  "success": true,
  "message": "AI configuration generation job queued successfully", // or "AI configuration refinement job queued successfully"
  "data": {
    "jobId": "string",
    "statusUrl": "/api/v1/jobs/string"
  },
  "timestamp": "string (ISO 8601)"
}

Fields:

Error Responses

Job Status and Result

Use the statusUrl (e.g., GET /api/v1/jobs/{jobId}) provided in the 202 response to track the job’s progress. The job data will be updated with status messages like generating, refining, testing, fixing, and include tokensUsed and estimatedCost.

When the job status is completed, the result field in the job status response will contain the generated or refined scraping configuration JSON object.

If the job status is failed, the failedReason field will contain details about the failure (e.g., max iterations reached, persistent validation errors).