PHP code example of sharpapi / php-custom-workflow

1. Go to this page and download the library: Download sharpapi/php-custom-workflow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sharpapi / php-custom-workflow example snippets




harpAPI\CustomWorkflow\CustomWorkflowClient;
use GuzzleHttp\Exception\GuzzleException;

$client = new CustomWorkflowClient(apiKey: 'your_api_key_here');

try {
    // Execute a JSON workflow
    $statusUrl = $client->executeWorkflow('my-sentiment-analyzer', [
        'text' => 'Great product!',
        'score' => 4.5,
    ]);

    // Optional: adjust polling settings
    $client->setApiJobStatusPollingInterval(10); // seconds
    $client->setApiJobStatusPollingWait(180);    // seconds total wait

    // Fetch results when ready
    $result = $client->fetchResults($statusUrl)->toArray();
    print_r($result);
} catch (GuzzleException $e) {
    echo $e->getMessage();
}

$statusUrl = $client->executeWorkflow('document-analyzer',
    params: ['description' => 'Annual report'],
    files: ['document' => '/path/to/file.pdf'],
);
$result = $client->fetchResults($statusUrl);

$workflows = $client->listWorkflows();

foreach ($workflows->workflows as $wf) {
    echo "{$wf->name} — /api/v1/custom/{$wf->slug}\n";
}

$wf = $client->describeWorkflow('my-sentiment-analyzer');

echo $wf->inputMode->label();           // "JSON"
echo count($wf->

use SharpAPI\CustomWorkflow\Exceptions\ValidationException;

try {
    // Fetches schema, validates params, then executes — one call
    $statusUrl = $client->validateAndExecute('my-analyzer', ['text' => 'hello']);
} catch (ValidationException $e) {
    print_r($e->getErrors());
    // ["unknown_field" => ["Unknown parameter"]]
}
bash
composer