### URL Extraction Example Source: https://nextrows.com/docs/api/getting-started Demonstrates how to extract data from a list of URLs using a natural language prompt. ```APIDOC ## URL Extraction ### Description Extract data directly from web pages by providing a list of URLs and a natural language prompt. ### Method POST ### Endpoint /v1/extract ### Parameters #### Request Body - **type** (string) - Required - The type of extraction, should be 'url'. - **data** (array of strings) - Required - A list of URLs to extract data from. - **prompt** (string) - Required - A natural language prompt describing the data to extract. - **schema** (object) - Optional - A JSON schema to validate the extracted data. ### Request Example ```json { "type": "url", "data": ["https://example.com/page1", "https://example.com/page2"], "prompt": "Extract all product information including name, price, and rating", "schema": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"}, "rating": {"type": "number"} }, "required": ["name", "price"] } } } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of extracted data objects. #### Response Example ```json { "success": true, "data": [ { "name": "Example Product 1", "price": 19.99, "rating": 4.5 } ] } ``` ``` -------------------------------- ### Multiple URL Processing Example Source: https://nextrows.com/docs/api/getting-started Demonstrates how to submit multiple URLs in a single request for batch processing. This is efficient for extracting data from several related pages. ```json { "type": "url", "data": [ "https://site1.com/page1", "https://site1.com/page2", "https://site2.com/products" ], "prompt": "Extract product information from each page" } ``` -------------------------------- ### Text Extraction Example Source: https://nextrows.com/docs/api/getting-started Demonstrates how to extract structured data from raw text content using a natural language prompt. ```APIDOC ## Text Extraction ### Description Extract structured data from raw text content you provide, using a natural language prompt. ### Method POST ### Endpoint /v1/extract ### Parameters #### Request Body - **type** (string) - Required - The type of extraction, should be 'text'. - **data** (array of strings) - Required - A list of text blocks to extract data from. - **prompt** (string) - Required - A natural language prompt describing the data to extract. - **schema** (object) - Optional - A JSON schema to validate the extracted data. ### Request Example ```json { "type": "text", "data": ["Product: iPhone 14\nPrice: $999\nRating: 4.5/5"], "prompt": "Extract product details in a structured format", "schema": { "type": "array", "items": { "type": "object", "properties": { "product": {"type": "string"}, "price": {"type": "string"}, "rating": {"type": "string"} }, "required": ["product", "price"] } } } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of extracted data objects. #### Response Example ```json { "success": true, "data": [ { "product": "iPhone 14", "price": "$999", "rating": "4.5/5" } ] } ``` ``` -------------------------------- ### URL Extraction Example Source: https://nextrows.com/docs/api/getting-started Demonstrates how to configure a request to extract data from a list of URLs. It specifies the extraction type, provides the target URLs, and includes a natural language prompt to guide the AI. ```json { "type": "url", "data": ["https://example.com/page1", "https://example.com/page2"], "prompt": "Extract all product information including name, price, and rating" } ``` -------------------------------- ### Example of Specific Prompt for Data Extraction Source: https://nextrows.com/docs/api/troubleshooting Illustrates the difference between a broad and a specific prompt for data extraction. The first example ('Extract all information') is less efficient, while the second ('Extract only product name and price from the product info section') is more targeted. ```json // ❌ Processes entire page {"prompt": "Extract all information"} // ✅ Targets specific data {"prompt": "Extract only product name and price from the product info section"} ``` -------------------------------- ### Authentication Source: https://nextrows.com/docs/api/getting-started Details on how to authenticate your API requests using an API key. ```APIDOC ## Authentication ### Description All requests to the NextRows API require authentication. You must include your API key in the `Authorization` header of your requests. ### Method All HTTP Methods (GET, POST, PUT, DELETE, etc.) ### Endpoint All API Endpoints ### Parameters #### Headers - **Authorization** (string) - Required - Your API key prefixed with 'Bearer '. Example: `Bearer sk-nr-your-api-key-here` ### Security Keep your API key secure. Never expose it in client-side code or public repositories. ### Request Example ```bash curl -X POST https://api.nextrows.com/v1/extract \ -H "Authorization: Bearer sk-nr-your-api-key" \ -H "Content-Type: application/json" \ -d '{...}' ``` ``` -------------------------------- ### General API Request and Response Source: https://nextrows.com/docs/api/getting-started Provides a general structure for making API requests and understanding successful and error responses. ```APIDOC ## Making Requests ### Description This section outlines the general structure for making requests to the NextRows API and the format of typical responses. ### Method POST (for extraction requests) ### Endpoint /v1/extract ### Request Body Example ```json { "type": "url", "data": ["https://example.com"], "prompt": "Your extraction prompt here" } ``` ### Response Format #### Success Response (200) - **success** (boolean) - true if the operation was successful. - **data** (array) - The extracted data, if successful. ```json { "success": true, "data": [ { "field1": "value1", "field2": "value2" } ] } ``` #### Error Response - **success** (boolean) - false if the operation failed. - **error** (string) - A message describing the error. ```json { "success": false, "error": "Failed to extract data from URLs" } ``` ``` -------------------------------- ### Specify Data Types and Formats in Extraction Prompts Source: https://nextrows.com/docs/api/troubleshooting Shows how to guide data extraction to yield specific data types and formats. Examples include requesting price as a number and dates in 'YYYY-MM-DD' format. ```json {"prompt": "Extract price as a number without currency symbols, and date in YYYY-MM-DD format"} ``` -------------------------------- ### Text Extraction Example Source: https://nextrows.com/docs/api/getting-started Shows how to extract structured data from raw text content. This is useful when you already have the web page content as text and want to parse specific information from it. ```json { "type": "text", "data": ["Product: iPhone 14\nPrice: $999\nRating: 4.5/5"], "prompt": "Extract product details in a structured format" } ``` -------------------------------- ### Run NextRows App (Table) - Java Example Source: https://nextrows.com/docs/api/apps/runAppTable Demonstrates how to run a NextRows app and get results as table data using Java. This example utilizes Apache HttpClient to perform the POST request, including setting headers and the JSON request body. ```java import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.json.JSONObject; public class RunAppTable { public static void main(String[] args) { String url = "https://api.nextrows.com/v1/apps/run/table"; String token = "YOUR_API_TOKEN"; String appId = "abc123xyz"; try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost request = new HttpPost(url); JSONObject jsonBody = new JSONObject(); jsonBody.put("appId", appId); JSONObject input = new JSONObject(); input.put("key", "max-items"); input.put("value", 10); jsonBody.accumulate("inputs", input); StringEntity entity = new StringEntity(jsonBody.toString()); request.setEntity(entity); request.setHeader("Authorization", "Bearer " + token); request.setHeader("Content-Type", "application/json"); org.apache.http.client.ResponseHandler responseHandler = response -> { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { return EntityUtils.toString(response.getEntity()); } else { throw new org.apache.http.client.ClientProtocolException("Unexpected response status: " + status); } }; String responseBody = client.execute(request, responseHandler); System.out.println(responseBody); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Example Prompt for Extracting Title, Headings, and Price Source: https://nextrows.com/docs/api/troubleshooting An advanced JSON prompt for extracting multiple types of information: the page title, main headings, and any associated price information. ```json {"prompt": "Extract title, headings, and any price information"} ``` -------------------------------- ### Make First API Request with JavaScript Source: https://nextrows.com/docs/api/quick-start This JavaScript example demonstrates how to make an asynchronous POST request to the NextRows API using the `fetch` API. It includes setting the necessary headers for authentication and content type, and sending a JSON body containing the extraction details. The response is then parsed as JSON and logged to the console. ```javascript const response = await fetch('https://api.nextrows.com/v1/extract', { method: 'POST', headers: { 'Authorization': 'Bearer sk-nr-your-api-key', 'Content-Type': 'application/json' }, body: JSON.stringify({ type: 'url', data: ['https://example.com/products'], prompt: 'Extract product names, prices, and descriptions' }) }); const result = await response.json(); console.log(result); ``` -------------------------------- ### Example Prompt for Extracting Title and Main Headings Source: https://nextrows.com/docs/api/troubleshooting A JSON prompt designed to extract both the page title and its main headings, increasing the complexity from a simple title extraction. ```json {"prompt": "Extract title and main headings"} ``` -------------------------------- ### Prompt Specificity Examples (Text) Source: https://nextrows.com/docs/api/examples Illustrates the difference between vague and specific prompts for data extraction. Specific prompts clearly define the desired data points and their formats, leading to more accurate results. ```text # ❌ Vague "Extract data from this page" # ✅ Specific "Extract product name, price in USD, customer rating (1-5 stars), and stock status (in stock/out of stock) from each product listing" ``` -------------------------------- ### API Authentication Header Source: https://nextrows.com/docs/api/getting-started Demonstrates the required HTTP header for authenticating API requests. Replace 'sk-nr-your-api-key-here' with your actual API key. ```http Authorization: Bearer sk-nr-your-api-key-here ``` -------------------------------- ### Process Product URLs and Save to JSON (Python) Source: https://nextrows.com/docs/api/examples This snippet demonstrates how to process a list of product URLs using the extractor to get product name, price, and availability. The results are then saved to a JSON file with indentation. It requires the 'json' library and assumes an 'extractor' object is available. ```python product_urls = [f"https://store.com/product/{i}" for i in range(1, 101)] results = extractor.process_large_dataset( product_urls, "Extract product name, price, and availability", schema={ "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"}, "available": {"type": "boolean"} } } } ) import json with open('products.json', 'w') as f: json.dump(results, f, indent=2) ``` -------------------------------- ### Handle Missing Data in Extraction Prompts Source: https://nextrows.com/docs/api/troubleshooting Demonstrates how to instruct the extraction process to handle missing data gracefully. The examples show prompts that either don't consider missing data or explicitly define a fallback value like 'N/A'. ```json // ❌ Doesn't handle missing data {"prompt": "Extract price and rating"} // ✅ Handles missing data explicitly {"prompt": "Extract price and rating, use 'N/A' if not available"} ``` -------------------------------- ### POST /v1/extract Source: https://nextrows.com/docs/api/quick-start Extracts structured data from a given URL or HTML content using natural language prompts. ```APIDOC ## POST /v1/extract ### Description This endpoint allows you to extract structured data from a website or provided HTML content. You describe the data you need in natural language, and NextRows uses AI to extract it. It supports extraction from URLs or direct HTML input. ### Method POST ### Endpoint https://api.nextrows.com/v1/extract ### Parameters #### Request Body - **type** (string) - Required - Specifies the type of input data. Accepted values: "url" or "html". - **data** (array of strings) - Required - An array containing the URL(s) or HTML content to process. - **prompt** (string) - Required - A natural language description of the data to extract. ### Request Example ```json { "type": "url", "data": ["https://example.com/products"], "prompt": "Extract product names, prices, and descriptions" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the extraction was successful. - **data** (array of objects) - An array containing the extracted structured data. #### Response Example ```json { "success": true, "data": [ { "product_name": "Wireless Headphones", "price": "$99.99", "description": "High-quality wireless headphones with noise cancellation" }, { "product_name": "Smart Watch", "price": "$299.99", "description": "Feature-rich smartwatch with health tracking" } ] } ``` ``` -------------------------------- ### Batch URL Processing Example Source: https://nextrows.com/docs/index An example JSON payload illustrating batch processing of multiple URLs in a single request. This is efficient for extracting data from a catalog of products across different sites. ```json { "type": "url", "data": [ "https://site1.com/products", "https://site2.com/products", "https://site3.com/products" ], "prompt": "Extract product catalog from each site" } ``` -------------------------------- ### Example Prompt for Initial Page Title Extraction Source: https://nextrows.com/docs/api/troubleshooting A simple JSON prompt used for initial debugging or basic data extraction, specifically targeting the page's title. ```json {"prompt": "Extract page title"} ``` -------------------------------- ### Batch Processing Framework Source: https://nextrows.com/docs/api/examples Provides a framework for efficiently processing large datasets by handling extractions in batches, including rate limiting and error handling. ```APIDOC ## Batch Processing Framework ### Description This class, `BatchExtractor`, facilitates the processing of large numbers of URLs by breaking them down into manageable batches. It includes features for setting batch size, adding delays between batches for rate limiting, and logging progress and errors. ### Method N/A (This is a client-side class) ### Endpoint N/A (This class interacts with the `/v1/extract` endpoint) ### Parameters #### Class Initialization (`BatchExtractor`) - **api_key** (string) - Required - Your Nextrows API key. - **batch_size** (integer) - Optional - The number of URLs to process in each batch. Defaults to 10. - **delay** (float) - Optional - The time in seconds to wait between processing batches. Defaults to 1.0. #### `process_large_dataset` Method - **all_urls** (array of strings) - Required - A list of all URLs to be processed. - **prompt** (string) - Required - The prompt to be used for each extraction batch. - **schema** (object) - Optional - The JSON schema to structure the output for each batch. ### Request Example (Usage) ```python import requests import time from typing import List, Dict, Any import logging class BatchExtractor: def __init__(self, api_key: str, batch_size: int = 10, delay: float = 1.0): self.api_key = api_key self.batch_size = batch_size self.delay = delay self.base_url = "https://api.nextrows.com/v1/extract" logging.basicConfig(level=logging.INFO) self.logger = logging.getLogger(__name__) def extract_batch(self, urls: List[str], prompt: str, schema: Dict = None) -> List[Dict[Any, Any]]: """Extract data from a batch of URLs""" request_data = { "type": "url", "data": urls, "prompt": prompt } if schema: request_data["schema"] = schema response = requests.post( self.base_url, headers={"Authorization": f"Bearer {self.api_key}"}, json=request_data ) if response.status_code == 200: return response.json().get('data', []) else: self.logger.error(f"Batch failed: {response.status_code} - {response.text}") return [] def process_large_dataset(self, all_urls: List[str], prompt: str, schema: Dict = None) -> List[Dict[Any, Any]]: """Process a large dataset in batches""" all_results = [] total_batches = (len(all_urls) + self.batch_size - 1) // self.batch_size self.logger.info(f"Processing {len(all_urls)} URLs in {total_batches} batches") for i in range(0, len(all_urls), self.batch_size): batch_urls = all_urls[i:i + self.batch_size] batch_num = (i // self.batch_size) + 1 self.logger.info(f"Processing batch {batch_num}/{total_batches} ({len(batch_urls)} URLs)") try: batch_results = self.extract_batch(batch_urls, prompt, schema) all_results.extend(batch_results) self.logger.info(f"Batch {batch_num} completed: {len(batch_results)} items extracted") if i + self.batch_size < len(all_urls): time.sleep(self.delay) except Exception as e: self.logger.error(f"Batch {batch_num} failed: {e}") continue self.logger.info(f"Total extraction completed: {len(all_results)} items") return all_results # Usage example extractor = BatchExtractor("sk-nr-your-api-key", batch_size=5, delay=2.0) # Define your research URLs and prompt research_urls = [ "https://arxiv.org/abs/1706.03762", "https://arxiv.org/abs/2005.11401", "https://arxiv.org/abs/1905.11403", "https://arxiv.org/abs/1803.08475", "https://arxiv.org/abs/2103.15981", "https://arxiv.org/abs/2201.05785" ] paper_prompt = "Extract academic paper details: Paper title, Authors, Publication date, Abstract." # Process the large dataset extracted_data = extractor.process_large_dataset(research_urls, paper_prompt) print(extracted_data) ``` ### Response #### Success Response (200) - **data** (array of objects) - A list containing the extracted data from all processed batches. #### Response Example ```json [ { "title": "Attention Is All You Need", "authors": ["Ashish Vaswani", "Noam Shazeer", ...], "publication_date": "2017-06-12", "abstract": "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks..." }, { "title": "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer", "authors": ["Colin Raffel", "Noam Shazeer", ...], "publication_date": "2020-05-28", "abstract": "We introduce a unified text-to-text transformer, T5, which frames all NLP tasks into a text-to-text format..." } ] ``` ``` -------------------------------- ### Extract Basic Job Listings (cURL) Source: https://nextrows.com/docs/api/examples This example demonstrates how to extract basic job listing information, such as title, company, location, salary, experience, and deadline, from career websites using a cURL command. It sends a POST request to the NextRows API with specified parameters. ```bash curl -X POST https://api.nextrows.com/v1/extract \ -H "Authorization: Bearer sk-nr-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "type": "url", "data": ["https://jobs.example.com/tech-jobs"], "prompt": "Extract job title, company name, location, salary range, experience level, and application deadline for each job posting" }' ``` -------------------------------- ### Run NextRows App (Table) - C# Example Source: https://nextrows.com/docs/api/apps/runAppTable A C# code example for executing a NextRows app and retrieving data as a table. It uses `HttpClient` to send a POST request, including the API token, content type, and the JSON payload. ```csharp using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json.Linq; public class RunAppTable { public static async Task Main(string[] args) { var url = "https://api.nextrows.com/v1/apps/run/table"; var token = "YOUR_API_TOKEN"; var appId = "abc123xyz"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); var payload = new JObject { ["appId"] = appId, ["inputs"] = new JArray( new JObject { ["key"] = "max-items", ["value"] = 10 } ) }; var content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json"); try { var response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode(); // Throw if HTTP status code is not 2xx var responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } catch (HttpRequestException e) { Console.WriteLine($"Request error: {e.Message}"); } } } } ``` -------------------------------- ### Extract E-commerce Products with Schema Validation (Python) Source: https://nextrows.com/docs/api/examples This Python example shows how to extract product details, including specific data types and validation rules, from a list of URLs. It leverages the NextRows API with a defined JSON schema to ensure data quality for production environments. Requires the 'requests' library. ```python import requests def extract_products_with_validation(urls): response = requests.post( "https://api.nextrows.com/v1/extract", headers={"Authorization": "Bearer sk-nr-your-api-key"}, json={ "type": "url", "data": urls, "prompt": "Extract product name, price in USD as number, rating as decimal, stock quantity, and product URL", "schema": { "type": "array", "items": { "type": "object", "properties": { "product_name": {"type": "string", "minLength": 1}, "price": {"type": "number", "minimum": 0}, "rating": {"type": "number", "minimum": 0, "maximum": 5}, "stock_quantity": {"type": "integer", "minimum": 0}, "product_url": {"type": "string", "format": "uri"} }, "required": ["product_name", "price"] } } } ) return response.json() # Usage product_urls = [ "https://store.com/electronics", "https://store.com/clothing", "https://store.com/home-garden" ] results = extract_products_with_validation(product_urls) ``` -------------------------------- ### Run NextRows App (Table) - JavaScript Example Source: https://nextrows.com/docs/api/apps/runAppTable Provides a JavaScript code snippet for running a NextRows app and fetching results as table data. This example uses the `fetch` API to make a POST request to the /v1/apps/run/table endpoint with the necessary authentication and payload. ```javascript const appId = "abc123xyz"; const token = "YOUR_API_TOKEN"; fetch("https://api.nextrows.com/v1/apps/run/table", { method: "POST", headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/json" }, body: JSON.stringify({ appId: appId, inputs: [ { key: "max-items", value: 10 } ] }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error("Error:", error)); ``` -------------------------------- ### Schema Evolution Source: https://nextrows.com/docs/api/features/schema-validation Demonstrates how to evolve schemas over time, starting from a basic version and adding more fields and constraints. ```APIDOC ## Schema Evolution ### Description Shows how to incrementally build and modify schemas. ### Version 1 - Basic Schema ```json { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"} } } ``` ### Version 2 - Enhanced Schema ```json { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"}, "currency": {"type": "string", "default": "USD"}, "availability": {"type": "boolean", "default": true} }, "required": ["name", "price"] } ``` ``` -------------------------------- ### Extract E-commerce Product Data with NextRows Source: https://nextrows.com/docs/api/getting-started This snippet demonstrates how to structure a prompt to extract key product information from e-commerce websites. It focuses on product name, pricing, ratings, reviews, and availability. Ensure your prompt clearly defines each required field. ```json { "prompt": "Extract product name, current price, original price if on sale, rating score, number of reviews, and availability status" } ``` -------------------------------- ### Schema Validation Example for Job Listings Source: https://nextrows.com/docs/index An example JSON payload demonstrating how to use the 'schema' parameter for validating extracted job listing data. This ensures the output conforms to a predefined structure with specific types and required fields. ```json { "type": "url", "data": ["https://jobs.example.com"], "prompt": "Extract job listings", "schema": { "type": "array", "items": { "type": "object", "properties": { "title": { "type": "string", "minLength": 1 }, "company": { "type": "string" }, "salary": { "type": "number", "minimum": 0 }, "location": { "type": "string" } }, "required": ["title", "company"] } } } ``` -------------------------------- ### Schema Design: Start Simple, Add Complexity Source: https://nextrows.com/docs/api/features/schema-validation Illustrates the progression from a basic schema to a more complex one. It emphasizes starting with essential fields and gradually adding complexity like patterns and enums for better data validation. ```json { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string", "pattern": "^[A-Z][a-z\\s]+$"}, "price": {"type": "number", "multipleOf": 0.01, "minimum": 0.01}, "category": {"type": "string", "enum": ["electronics", "clothing", "books"]} } } } ``` ```json { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"} }, "required": ["name"] } } ``` -------------------------------- ### API Response Examples Source: https://nextrows.com/docs/api/extract/extract Examples of API responses for the /v1/extract endpoint. This includes a successful extraction (200), and common error responses for bad requests (400), unauthorized access (401), exhausted credits (402), and internal server errors (500). ```json { "success": true, "data": [ [ "Rank", "Name", "Revenues ($M)", "Revenue Percent Change", "Profits ($M)", "Profits Percent Change", "Assets ($M)", "Employees", "Change in Rank", "Years on Global 500 List" ], [ "1", "Walmart", "648,125", "6%", "15,511", "32.8%", "252,399", "2,100,000", "-", "30" ], [ "2", "Amazon", "574,785", "11.8%", "30,425", "", "527,854", "1,525,000", "2", "16" ], [ "..." ] ] } ``` ```json { "success": false, "error": "Bad request" } ``` ```json { "success": false, "error": "Unauthorized" } ``` ```json { "success": false, "error": "Credits exhausted" } ``` ```json { "success": false, "error": "Internal server error" } ``` -------------------------------- ### POST /v1/extract - E-commerce Product Extraction with Schema Validation Source: https://nextrows.com/docs/api/examples Enhances product extraction by including schema validation to ensure data quality. This is recommended for production environments. ```APIDOC ## POST /v1/extract (with Schema Validation) ### Description Extracts product details from e-commerce sites and validates the extracted data against a provided schema, ensuring data quality for production use. ### Method POST ### Endpoint `/v1/extract` ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body - **type** (string) - Required - Specifies the data source type, e.g., "url". - **data** (array of strings) - Required - A list of URLs to process. - **prompt** (string) - Required - The instructions for data extraction, including desired data types and formats. - **schema** (object) - Optional - A JSON schema object used for validating the extracted data. It defines the expected structure, types, and constraints of the output. ### Request Example (Python) ```python import requests response = requests.post( "https://api.nextrows.com/v1/extract", headers={"Authorization": "Bearer sk-nr-your-api-key"}, json={ "type": "url", "data": ["https://store.com/electronics"], "prompt": "Extract product name, price in USD as number, rating as decimal, stock quantity, and product URL", "schema": { "type": "array", "items": { "type": "object", "properties": { "product_name": {"type": "string", "minLength": 1}, "price": {"type": "number", "minimum": 0}, "rating": {"type": "number", "minimum": 0, "maximum": 5}, "stock_quantity": {"type": "integer", "minimum": 0}, "product_url": {"type": "string", "format": "uri"} }, "required": ["product_name", "price"] } } } ) print(response.json()) ``` ### Response #### Success Response (200) Returns the extracted data, validated against the provided schema. The structure will match the schema definition. #### Response Example ```json { "success": true, "data": [ { "product_name": "Laptop Pro X", "price": 1299.99, "rating": 4.8, "stock_quantity": 50, "product_url": "https://store.com/electronics/laptop-pro-x" } ] } ``` ``` -------------------------------- ### Verify URL Accessibility with cURL Source: https://nextrows.com/docs/api/troubleshooting Shows how to use cURL with the '-I' option to quickly check the accessibility and headers of a target URL, useful for diagnosing extraction errors. ```shell curl -I https://target-website.com ``` -------------------------------- ### Run NextRows App (Table) - Go Example Source: https://nextrows.com/docs/api/apps/runAppTable Illustrates how to execute a NextRows app and retrieve table data using Go. This snippet demonstrates creating an HTTP client, constructing the request body, and sending a POST request to the API. ```go package main import ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" ) func main() { url := "https://api.nextrows.com/v1/apps/run/table" token := "YOUR_API_TOKEN" appId := "abc123xyz" requestBody, _ := json.Marshal(map[string]interface{}{ "appId": appId, "inputs": []map[string]interface{}{ {"key": "max-items", "value": 10} } }) req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody)) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Set("Authorization", "Bearer "+token) req.Header.Set("Content-Type", "application/json") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Text Extraction Request Example Source: https://nextrows.com/docs/index An example JSON payload for extracting data from provided text content. This format specifies the extraction type as 'text' and includes an array of text strings along with a prompt to guide the extraction. ```json { "type": "text", "data": [ "Product: iPhone 14\nPrice: $999\nRating: 4.5/5", "Product: Samsung Galaxy\nPrice: $899\nRating: 4.3/5" ], "prompt": "Extract product name, price, and rating" } ``` -------------------------------- ### Extract Basic E-commerce Product Info Source: https://nextrows.com/docs/api/examples Demonstrates extracting fundamental product details like name, price, rating, and availability from e-commerce websites using a simple URL-based request. ```json { "type": "url", "data": ["https://example-store.com/products"], "prompt": "Extract product name, price, rating, and availability status for each product" } ``` -------------------------------- ### Error API Response Format Source: https://nextrows.com/docs/api/getting-started Shows the format of an error response from the NextRows API. This provides information about the failure, aiding in troubleshooting. ```json { "success": false, "error": "Failed to extract data from URLs" } ``` -------------------------------- ### Make First API Request with cURL Source: https://nextrows.com/docs/api/quick-start This snippet demonstrates how to make a POST request to the NextRows API using cURL to extract data from a URL. It includes the necessary headers for authorization and content type, and a JSON payload specifying the extraction type, data source, and a natural language prompt. Ensure you replace 'sk-nr-your-api-key' with your actual API key. ```bash curl -X POST https://api.nextrows.com/v1/extract \ -H "Authorization: Bearer sk-nr-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "type": "url", "data": ["https://example.com/products"], "prompt": "Extract product names, prices, and descriptions" }' ``` -------------------------------- ### Successful API Response Format Source: https://nextrows.com/docs/api/getting-started Illustrates the structure of a successful response from the NextRows API. It indicates success and contains the extracted data in a structured format. ```json { "success": true, "data": [ { "field1": "value1", "field2": "value2" } ] } ``` -------------------------------- ### Define Data Schema for Validation Source: https://nextrows.com/docs/api/troubleshooting An example of a JSON schema used for validating extracted data. This schema defines the expected structure, types, and constraints (like minimum length) for the data. ```json { "schema": { "type": "array", "items": { "type": "object", "properties": { "title": {"type": "string", "minLength": 1}, "price": {"type": "string"} }, "required": ["title"] } } } ``` -------------------------------- ### Schema Validation Configuration Source: https://nextrows.com/docs/api/getting-started Illustrates how to define a JSON schema to ensure the extracted data conforms to expected structures and data types. This enhances data quality and consistency. ```json { "type": "url", "data": ["https://jobs.example.com"], "prompt": "Extract job postings", "schema": { "type": "array", "items": { "type": "object", "properties": { "title": {"type": "string"}, "company": {"type": "string"}, "salary": {"type": "string"}, "location": {"type": "string"}, "posted_date": {"type": "string"} }, "required": ["title", "company"] } } } ``` -------------------------------- ### Test Extraction with Specific JSON Payload Source: https://nextrows.com/docs/api/troubleshooting An example of a JSON payload used to test data extraction from a URL. This payload specifies the data type as 'url', provides a list of URLs, and includes a prompt for extraction. ```json { "type": "url", "data": ["https://httpbin.org/html"], "prompt": "Extract any text content" } ``` -------------------------------- ### Define Data Schema for Type Conversion Source: https://nextrows.com/docs/api/troubleshooting An example of a JSON schema that can be used for type conversion during data validation. It specifies the expected types and formats for properties like 'price' (number) and 'date' (string with date format). ```json { "schema": { "properties": { "price": {"type": "number"}, "date": {"type": "string", "format": "date"} } } } ``` -------------------------------- ### Basic API Request using cURL Source: https://nextrows.com/docs/api/getting-started Provides a cURL command for making a basic extraction request to the NextRows API. It includes the necessary headers for authorization and content type, along with the JSON payload. ```bash curl -X POST https://api.nextrows.com/v1/extract \ -H "Authorization: Bearer sk-nr-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "type": "url", "data": ["https://example.com"], "prompt": "Your extraction prompt here" }' ``` -------------------------------- ### Shell: Check Nextrows API Credit Usage Source: https://nextrows.com/docs/index This command-line example shows how to retrieve the current credit balance for your Nextrows API account using `curl`. It sends a GET request to the /v1/credits endpoint with the necessary authorization header. ```bash curl -X GET https://api.nextrows.com/v1/credits \ -H "Authorization: Bearer sk-nr-your-api-key" ``` -------------------------------- ### Extract News Article Data with NextRows Source: https://nextrows.com/docs/api/getting-started This snippet illustrates a prompt designed to extract key information from news articles. It targets the headline, author, publication date, article text, and relevant tags or categories. The prompt should be specific to ensure all desired content is captured. ```json { "prompt": "Extract article headline, author name, publication date, article text, and tags or categories" } ``` -------------------------------- ### Extract Job Posting Data with NextRows Source: https://nextrows.com/docs/api/getting-started This snippet shows how to craft a prompt for extracting essential details from job board postings. It includes job title, company, location, salary, experience level, and application deadline. Clear specification of fields is crucial for accurate extraction. ```json { "prompt": "Extract job title, company name, location, salary range, experience level, and application deadline" } ``` -------------------------------- ### Schema Evolution Example: Version 1 to Version 2 Source: https://nextrows.com/docs/api/features/schema-validation Illustrates how a JSON schema can be evolved over time. Version 1 defines basic 'name' and 'price' properties. Version 2 enhances the schema by adding optional 'currency' and 'availability' fields with default values, while retaining the original required fields. ```json { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"} } } ``` ```json { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"}, "currency": {"type": "string", "default": "USD"}, "availability": {"type": "boolean", "default": true} }, "required": ["name", "price"] } ``` -------------------------------- ### Schema Generation with Python (genson) Source: https://nextrows.com/docs/api/features/schema-validation Demonstrates how to generate a JSON schema from sample data using the 'genson' Python library. This is useful for creating schemas automatically based on existing data structures. ```python from genson import SchemaBuilder # Generate schema from sample data builder = SchemaBuilder() builder.add_object({"name": "Product A", "price": 99.99}) builder.add_object({"name": "Product B", "price": 149.50}) schema = builder.to_schema() print(schema) ``` -------------------------------- ### Run NextRows App (Table) - cURL Example Source: https://nextrows.com/docs/api/apps/runAppTable Demonstrates how to execute a published NextRows app and retrieve results as table data using a cURL command. It includes the endpoint, authentication header, and a sample JSON request body with appId and inputs. ```shell curl -X POST "https://api.nextrows.com/v1/apps/run/table" \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "appId": "abc123xyz", "inputs": [ { "key": "max-items", "value": 10 } ] }' ``` -------------------------------- ### URL Extraction Request Example Source: https://nextrows.com/docs/index An example JSON payload for performing data extraction directly from a list of URLs. This format specifies the extraction type as 'url' and provides an array of URLs along with a natural language prompt. ```json { "type": "url", "data": [ "https://example.com/page1", "https://example.com/page2" ], "prompt": "Extract product information" } ``` -------------------------------- ### Schema Validation for Data Extraction (Python) Source: https://nextrows.com/docs/api/examples Compares the recommended approach of using schema validation for data extraction against a less recommended approach without validation. It highlights the structure for defining required properties like 'name' and 'price' with specific constraints. ```python # Without validation (not recommended) {"prompt": "Extract product data"} # With validation (recommended) { "prompt": "Extract product data", "schema": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string", "minLength": 1}, "price": {"type": "number", "minimum": 0} }, "required": ["name", "price"] } } } ``` -------------------------------- ### Make First API Request with Python Source: https://nextrows.com/docs/api/quick-start This Python script shows how to send a POST request to the NextRows API to extract data. It utilizes the `requests` library to send JSON data, including the API key for authorization, the target URL, and a natural language prompt. The script prints the JSON response received from the API. ```python import requests url = "https://api.nextrows.com/v1/extract" headers = { "Authorization": "Bearer sk-nr-your-api-key", "Content-Type": "application/json" } data = { "type": "url", "data": ["https://example.com/products"], "prompt": "Extract product names, prices, and descriptions" } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` -------------------------------- ### cURL HTTP Request Example Source: https://nextrows.com/docs/api/features This cURL command demonstrates how to make a request to the NextRows API from the command line. It's useful for simple testing and shell scripting, showcasing the API's accessibility via standard HTTP clients. ```bash curl -X POST https://api.nextrows.com/extract \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "Extract all image URLs from the page." }' ```