Integrate the Lead Enrichment API in PHP

November 29, 2026
Integrate the Lead Enrichment API in PHP

When a signup or CSV import contains only a company domain, your PHP application needs a way to add useful context without making an analyst research every lead. This guide shows how to send domains to Klazify, interpret the company and categorization data, and design an import that handles missing results and repeat domains safely.

Why categorize domains during lead enrichment?

Documentation describes the REST integration for Klazify’s domain intelligence service. Its categorization endpoint can return website categories alongside company information, giving a CRM both a classification and business context from the same lookup.

Illustration: Integrate the Lead Enrichment API in PHP

Content analysis is useful when a domain name alone says little about what a business does. Klazify analyzes website content rather than relying only on metadata, supports multilingual sites, and maps content to a hierarchical taxonomy that includes IAB categories. For a lead imported from a global list, that can provide a more useful starting point than a rule based solely on keywords in the domain.

A returned category is still evidence for a workflow, not a decision by itself. Use it to route a lead for review, populate an internal segment, or help an analyst understand the company. Validate the result against your own requirements before using it for automated filtering or compliance decisions.

Prepare a PHP import

Lead enrichment and CSV imports use the same categorization endpoint: https://www.klazify.com/api/categorize. Process one domain per call. For a signup, make the lookup asynchronously if the user should not have to wait for enrichment; for a CSV, put the rows into a worker queue and store the result against each lead.

Configure the request method, authentication, and domain input using the Documentation before running a request. Keep credentials outside the source repository, and make the domain passed to the API explicit in your request configuration.

Process a CSV and reuse results

The following PHP example reads domains from the first column of a CSV file and writes one JSON record per input row. It expects a local request-config.php file to define configureKlazifyRequest($handle, $domain), which applies the documented request settings and credentials to the cURL handle. This separation keeps the import logic independent of authentication and request formatting.

<?php
require __DIR__ . '/request-config.php';

$input = fopen($argv[1] ?? '', 'r');
if ($input === false) {
    throw new RuntimeException('Could not open the CSV file.');
}

$cache = [];

while (($row = fgetcsv($input)) !== false) {
    $domain = strtolower(trim($row[0] ?? ''));

    if ($domain === '') {
        continue;
    }

    if (!array_key_exists($domain, $cache)) {
        $handle = curl_init('https://www.klazify.com/api/categorize');
        if ($handle === false) {
            throw new RuntimeException('Could not initialize cURL.');
        }

        configureKlazifyRequest($handle, $domain);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

        $body = curl_exec($handle);
        $status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
        $error = curl_error($handle);
        curl_close($handle);

        if ($body === false || $status < 200 || $status >= 300) {
            fwrite(STDERR, "Lookup failed for $domain: $error\n");
            continue;
        }

        try {
            $result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
        } catch (JsonException $e) {
            fwrite(STDERR, "Invalid JSON for $domain\n");
            continue;
        }

        if (!is_array($result) || ($result['success'] ?? false) !== true) {
            fwrite(STDERR, "No successful result for $domain\n");
            continue;
        }

        $cache[$domain] = $result;
    }

    $result = $cache[$domain];
    $company = $result['objects']['company'] ?? [];
    $categories = $result['domain']['categories'] ?? [];

    echo json_encode([
        'input_domain' => $domain,
        'company_name' => $company['name'] ?? null,
        'country' => $company['countryCode'] ?? null,
        'categories' => $categories,
    ], JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE), PHP_EOL;
}

fclose($input);

Run the script with the path to your CSV as its argument after implementing the request configuration. The in-memory cache avoids repeated calls for the same normalized domain during one run. A production worker can use a shared cache so that separate imports and signup requests benefit too.

This example skips failed lookups rather than silently treating them as successful enrichments. In a production import, retain the original row and record its lookup status so it can be retried or reviewed. If the CSV has a header row, handle that separately rather than sending the column name as a domain.

Inspect a request from JavaScript

The same endpoint can be called from JavaScript. This example expects KLAZIFY_REQUEST_OPTIONS to contain JSON-encoded fetch options configured with the documented authentication and domain input. It prints the fields a lead pipeline is likely to inspect first.

const endpoint = "https://www.klazify.com/api/categorize";
const options = JSON.parse(process.env.KLAZIFY_REQUEST_OPTIONS);

const response = await fetch(endpoint, options);
if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}

const result = await response.json();
if (result.success !== true) {
  throw new Error("Enrichment did not succeed");
}

const company = result.objects?.company ?? {};
const categories = result.domain?.categories ?? [];

console.log(JSON.stringify({
  companyName: company.name ?? null,
  countryCode: company.countryCode ?? null,
  categories
}, null, 2));

Use a supported JavaScript runtime with fetch available. As with the PHP import, configure the request for the domain being processed and do not place credentials in logs or client-side code.

Read the enrichment response

The following is the supplied Klazify response example. Treat it as an illustration of the response structure, not as the result of a different domain lookup.

{
    "domain": {
        "categories": [
            {
                "confidence": 0.92,
                "name": "/Computers & Electronics/Consumer Electronics",
                "IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
            },
            {
                "confidence": 0.89,
                "name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
            }
        ],
        "social_media": null,
        "logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
    },
    "success": true,
    "objects": {
        "company": {
            "url": "https://www.apple.com/",
            "name": "Apple",
            "city": "Cupertino",
            "stateCode": "CA",
            "countryCode": "US",
            "employeesRange": "100K+",
            "revenue": 274515000000,
            "raised": null,
            "tags": [
                "E-commerce",
                "Consumer Electronics",
                "Mobile",
                "B2C"
            ],
            "tech": [
                "omniture_adobe_analytics",
                "atlassian_confluence",
                "successfactors",
                "apache_apex",
                "talend",
                "oracle_peoplesoft",
                "salesforce",
                "stripe",
                "dell_boomi_atomsphere",
                "gigya",
                "sage_50cloud",
                "quickbooks",
                "webmethods",
                "apache_tomcat",
                "alteryx",
                "tibco_rendezvous",
                "atlassian_jira",
                "..."
            ]
        }
    },
    "domain_registration_data": {
        "domain_age_date": "1987-02-19",
        "domain_age_days_ago": "13026",
        "domain_expiration_date": "2030-02-20",
        "domain_expiration_days_left": "123"
    },
    "similar_domains": [
        "bestbuy.com",
        "icloud.com",
        "microsoft.com",
        "macrumors.com",
        "google.com",
        "samsung.com",
        "twitter.com",
        "hp.com",
        "bhphotovideo.com",
        "dell.com"
    ]
}
Response fieldUse in a lead workflowHandling consideration
successIdentify a successful enrichment result.Check it in addition to the HTTP status.
domain.categoriesMap category names and available IAB information to internal segments.A domain can have multiple categories; retain their confidence values.
objects.companyPopulate company name, location, employee range, tags, and other available context.Fields can be absent or null; do not overwrite verified CRM data blindly.
domain.logo_url and domain.social_mediaProvide optional links for a lead-review interface.The sample has no social media value; render missing data gracefully.
domain_registration_dataAdd domain-age context for an analyst.Dates and days remaining change over time; retain the lookup time with the result.
similar_domainsOffer starting points for research.Do not assume a listed domain is a verified competitor or a new lead.

The first category in the sample includes an IAB mapping; the second does not show one. Code should therefore inspect each category independently rather than assume every entry has the same keys. The confidence values are classification signals, not guarantees that a lead belongs in a particular sales segment.

The sample also contains a revenue value, but the response shown does not establish its currency, period, or precision. Confirm the meaning of a field before displaying it as a financial fact or using it in a scoring rule. Similarly, the date-only registration values should not be treated as timestamps with an assumed timezone.

Make enrichment reliable at scale

Queue and pace calls. A CSV with many rows still requires one request per domain. Deduplicate before dispatching work, use a bounded number of workers, and configure pacing according to your account’s rate limits. Avoid treating an entire import as failed because one domain is unreachable.

Cache by normalized domain. Store the successful response with the normalized input domain and lookup time. Choose a refresh interval that suits your use case: a sales team may tolerate older context longer than a workflow auditing changing content. The PHP example’s cache lasts only for the process; a shared persistent cache is needed across workers.

Keep unknown separate from negative. A new, unreachable, or unclassified domain is not proof that the company lacks a category. Record an unresolved state and retry according to your operational policy. Klazify states that failed or unreachable calls are not billed, but your pipeline should still prevent repeated failures from consuming worker capacity.

Map categories deliberately. Maintain a versioned mapping from Klazify category names or available IAB values to your CRM’s own segments. Preserve the original category and confidence alongside the mapped value so an analyst can audit the decision. When a result contains multiple categories, decide whether your workflow stores all matches, selects one, or sends the lead for review.

Protect existing data. Enrichment is most useful when it supplements a lead record. Store provenance and lookup time, and establish which fields may be automatically updated versus which require review. Monitor missing categories, request failures, and mapping gaps so a change in input quality does not silently degrade routing.

FAQ

Can I enrich a CSV in one API call?

Use the same REST endpoint for a CSV import and submit one domain per call. Deduplicate domains and queue the calls to control concurrency.

What should I do when a company field is missing?

Keep the field empty or mark it for review. A missing value should not erase a verified value already stored in your CRM.

Can I use category confidence as a lead score?

You can include it as an input, but category confidence describes the classification signal, not a company’s suitability as a customer. Validate any threshold against your own reviewed leads.

Where can I explore other integration options?

The MCP page provides another place to explore integration options. For the PHP workflow above, start with the REST request configuration in the Documentation.

Ready to test enrichment on your own lead domains? Register for a free account and configure your first lookup. The Starter plan is $39.99 per month with a seven-day trial.

Ready to use Klazify?

Start classifying websites, enriching company data, and exploring web intelligence.

Get Started Free