PHP code example of stitch-digital / nametodomain-php-sdk

1. Go to this page and download the library: Download stitch-digital/nametodomain-php-sdk 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/ */

    

stitch-digital / nametodomain-php-sdk example snippets


use NameToDomain\PhpSdk\NameToDomain;

// Single resolution (sync)
$result = NameToDomain::make($token)->resolve(
    company: 'Stitch Digital',
    country: 'GB'
);

// Batch enrichment (async)
$job = NameToDomain::make($token)->enrichBatch(
    items: [
        ['company' => 'Stripe', 'country' => 'US'],
        ['company' => 'Spotify', 'country' => 'SE'],
    ]
);

use NameToDomain\PhpSdk\NameToDomain;

// Single resolution (sync)
$result = NameToDomain::make($token)->resolve(
    company: 'Stitch Digital',
    country: 'GB'
);

// Batch enrichment (async)
$job = NameToDomain::make($token)->enrichBatch(
    items: [
        ['company' => 'Stripe', 'country' => 'US'],
        ['company' => 'Spotify', 'country' => 'SE'],
    ]
);

// Check batch job status and get results
$batchResult = NameToDomain::make($token)->enrichBatchJob(jobId: $job->id);

// Or iterate over all batch items (paginated)
$items = NameToDomain::make($token)->enrichBatchJobItems(jobId: $job->id)->collect()->all();

use NameToDomain\PhpSdk\NameToDomain;

$client = NameToDomain::make('your-api-token');

$client = new \NameToDomain\PhpSdk\NameToDomain(
    'your-api-token',
    'https://nametodomain.dev/api/v1',
    30
);

try {
    $client->resolve(company: '', country: 'US');
} catch (\NameToDomain\PhpSdk\Exceptions\ValidationException $exception) {
    $exception->getMessage(); // returns a string describing the errors
    
    $exception->getErrors(); // returns an array with all validation errors
    $exception->getErrorsForField('company'); // get errors for a specific field
}

try {
    $client->enrichJob(jobId: 'invalid-id');
} catch (\NameToDomain\PhpSdk\Exceptions\NameToDomainException $exception) {
    $exception->getMessage();
    $exception->response; // access the Saloon Response object for debugging
}

$result = NameToDomain::make($token)->resolve(
    company: 'Stitch Digital',
    country: 'GB'
);

$result = NameToDomain::make($token)->resolve(
    company: 'Stripe',
    country: 'US',
    emails: ['[email protected]', '[email protected]']
);

$job = NameToDomain::make($token)->enrich(
    company: 'Stripe',
    country: 'US',
    emails: ['[email protected]'],
    identifier: 'stripe-001'
);

// Poll for result
$result = NameToDomain::make($token)->enrichJob($job->id);
// When completed, $result->output is a JobItem with the enriched data

$job = NameToDomain::make($token)->enrich(
    company: 'Stripe',
    country: 'US',
    idempotencyKey: 'my-unique-idempotency-key'
);

$job = NameToDomain::make($token)->enrichBatch(
    items: [
        ['company' => 'Stripe', 'country' => 'US', 'emails' => ['[email protected]'], 'identifier' => 'stripe-001'],
        ['company' => 'Spotify', 'country' => 'SE', 'identifier' => 'spotify-001'],
    ]
);

$job = NameToDomain::make($token)->enrichBatch(
    items: [['company' => 'Stripe', 'country' => 'US']],
    idempotencyKey: 'my-unique-idempotency-key'
);

$result = NameToDomain::make($token)->enrichJob('01HQJXK8N3YWVF6BCMPG42X1TZ');
// $result->job and $result->output (JobItem or null)

$result = NameToDomain::make($token)->enrichBatchJob('01HQJXK8N3YWVF6BCMPG42X1TZ', page: 1, perPage: 50);
// $result->job, $result->output (JobItem[]), $result->pagination

$paginator = NameToDomain::make($token)->enrichBatchJobItems(jobId: $jobId);

foreach ($paginator->items() as $item) {
    if ($item->result && $item->result['domain']) {
        echo "{$item->input['company']}: {$item->result['domain']}\n";
    }
}

$items = NameToDomain::make($token)
    ->enrichBatchJobItems(jobId: $jobId)
    ->collect()
    ->all();

$paginator = NameToDomain::make($token)->enrichBatchJobItems(
    jobId: $jobId,
    page: 2,
    perPage: 100
);

use NameToDomain\PhpSdk\NameToDomain;
use NameToDomain\PhpSdk\Requests\Resolve\ResolveRequest;

$client = NameToDomain::make('your-api-token');
$request = new ResolveRequest('Stripe', 'US');

$response = $client->send($request)->dto();