API Details: Tours & Activities Product Categorization AI API
Description: Demonstrates how to use the toursAndActivitiesProductCategories() method to generate suitable categories for Tours & Activities products.
Code Snippet:
<?php
require 'vendor/autoload.php';
use SharpAPI\SharpApiService;
// Load environment variables
$apiKey = getenv('SHARP_API_KEY');
if (!$apiKey) {
throw new Exception("API key not found. Please set SHARP_API_KEY in your environment variables.");
}
// Initialize the SharpApiService
$sharpApi = new SharpApiService($apiKey);
try {
$statusUrl = $sharpApi->toursAndActivitiesProductCategories(
content: "Oasis of the Bay",
city: "Ha Long",
country: "Vietnam",
language: "English",
max_quantity: 10,
voice_tone: "neutral",
context: null
);
$resultJob = $sharpApi->fetchResults($statusUrl);
echo "Tours and Activities Product Categories Result:\n";
print_r(json_decode($resultJob->getResultJson(), true));
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}$resultJob->getResultJson() format example:
{
"data": {
"type": "api_job_result",
"id": "55bc3311-d16e-4949-83a0-d367b7f79f89",
"attributes": {
"status": "success",
"type": "tth_ta_product_categories",
"result": [
{
"name": "Boat Tours",
"weight": 9.5
},
{
"name": "Nature & Wildlife Tours",
"weight": 8.7
},
{
"name": "Water Sports",
"weight": 7.8
},
{
"name": "Sightseeing Cruises",
"weight": 9.2
},
{
"name": "Day Trips",
"weight": 8
},
{
"name": "Eco Tours",
"weight": 7.5
},
{
"name": "Adventure Tours",
"weight": 6.8
},
{
"name": "Cultural Tours",
"weight": 6
},
{
"name": "Multi-day Tours",
"weight": 5.5
},
{
"name": "Private Sightseeing Tours",
"weight": 5.2
}
]
}
}
}