Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save makowskid/4cadf2cc140a0ffd0cd90617bbb5259e to your computer and use it in GitHub Desktop.

Select an option

Save makowskid/4cadf2cc140a0ffd0cd90617bbb5259e to your computer and use it in GitHub Desktop.
SharpAPI.com PHP Client AI workflow API: Hospitality Product Categories Method Example

SharpAPI.com PHP Client AI workflow API: Hospitality Product Categories Method Example

API Details: Hospitality Product Categorization AI API

Description: Shows how to use the hospitalityProductCategories() method to generate suitable categories for Hospitality 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->hospitalityProductCategories(
          content: "Hotel Crystal 大人専用",
          city: "Tokyo",
          country:"Japan",
          language: "English",
          max_quantity:10,
          voice_tone: "neutral",
          context:null
    );
    $resultJob = $sharpApi->fetchResults($statusUrl);
    echo "Hospitality 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": "afb7cc23-23a5-479c-92a9-be983792dabc",
    "attributes": {
      "status": "success",
      "type": "tth_hospitality_product_categories",
      "result": [
        {
          "name": "Adult Only Hotels",
          "weight": 10
        },
        {
          "name": "Luxury Hotels",
          "weight": 8.5
        },
        {
          "name": "Boutique Hotels",
          "weight": 7.5
        },
        {
          "name": "Romantic Getaways",
          "weight": 7
        },
        {
          "name": "City Hotels",
          "weight": 6.5
        },
        {
          "name": "Couples Retreats",
          "weight": 6
        }
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment