<?php
$apiKey = getenv('UJEEBU_API_KEY') ?: 'YOUR_API_KEY';
// Define expected output schema (standard JSON Schema)
$schema = [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string', 'description' => 'Product name'],
'price' => ['type' => 'string', 'description' => 'Price with currency symbol'],
'currency' => ['type' => 'string', 'description' => 'Currency code'],
'rating' => ['type' => 'number', 'description' => 'Star rating 0-5'],
'total_reviews' => ['type' => 'number', 'description' => 'Number of reviews'],
'in_stock' => ['type' => 'boolean', 'description' => 'Whether product is in stock'],
'features' => [
'type' => 'array',
'items' => ['type' => 'string'],
'description' => 'Key product features'
]
],
'required' => ['name', 'price']
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.ujeebu.com/ai-scraper',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'ApiKey: ' . $apiKey,
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.com/product',
'prompt' => 'Extract all product information including name, price, rating, reviews, stock status, and key features',
'schema' => $schema,
'mm_model' => 'gpt-4o-mini'
])
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);
// Schema ensures consistent structure
$product = $data['data'] ?? null;
?>
{
"type": "object",
"properties": {
"name": {"type": "string", "description": "Product name"},
"price": {"type": "string", "description": "Price with currency symbol"},
"currency": {"type": "string", "description": "Currency code"},
"rating": {"type": "number", "description": "Star rating 0-5"},
"total_reviews": {"type": "number", "description": "Number of reviews"},
"in_stock": {"type": "boolean", "description": "Whether product is in stock"},
"features": {
"type": "array",
"items": {"type": "string"},
"description": "Key product features"
}
},
"required": ["name", "price"]
}