Integrate the Website Search API in PHP

November 27, 2026
Integrate the Website Search API in PHP

Your PHP application needs to find websites that match business criteria, but you do not have a list of domains to classify first. Klazify’s discovery endpoint searches its database using criteria such as category, country, technology and employee count; this guide shows how to call it from PHP, inspect the result and prepare it for an enrichment pipeline.

Choose discovery for finding websites

Documentation describes the request format for Klazify’s website search. Use discovery when your starting point is a set of filters, such as a category and a country, rather than a URL supplied by a user.

Illustration: Integrate the Website Search API in PHP

That distinction matters for lead generation and market research. A discovery search can produce candidates for a review queue, whereas the categorization endpoint is intended for classification and enrichment from a known URL or domain. A category match is useful evidence for an audit or CRM workflow, but it is not, by itself, a decision to block a site or approve an ad placement.

Klazify also provides IAB taxonomy mapping and company information. These signals can help a team translate website content into its own reporting categories, but discovery results and individual categorization responses should be treated as separate API outputs.

Prepare the discovery request

Send a POST request to https://www.klazify.com/api/discovery with Bearer authentication. The request body uses top_n and filters for category, country, technology and employees. A discovery request counts as one API call.

Before running the code, create a discovery request body using the filter syntax and accepted values in the documentation. Put that JSON in an environment variable named DISCOVERY_BODY, and put your API key in KLASIFY_API_KEY. Keeping the body separate makes it possible to change search criteria without editing the integration code.

The examples below submit the body as supplied and display the decoded response. Inspect the response for your search before adding field-specific extraction: the individual-domain response shown later illustrates categorization fields, not a guaranteed discovery response shape.

Call discovery from PHP

This example uses PHP’s cURL extension. It validates the request body as JSON before sending it, checks for transport and HTTP errors, and then validates the response as JSON.

<?php

$apiKey = getenv('KLASIFY_API_KEY');
$requestBody = getenv('DISCOVERY_BODY');

if (!$apiKey || !$requestBody) {
    throw new RuntimeException(
        'Set KLASIFY_API_KEY and DISCOVERY_BODY before running.'
    );
}

// Validate the supplied JSON without changing its structure.
json_decode($requestBody, true, 512, JSON_THROW_ON_ERROR);

$curl = curl_init('https://www.klazify.com/api/discovery');
curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $requestBody,
    CURLOPT_RETURNTRANSFER => true,
]);

$responseBody = curl_exec($curl);

if ($responseBody === false) {
    $message = curl_error($curl);
    curl_close($curl);
    throw new RuntimeException('Request failed: ' . $message);
}

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException('Discovery request returned HTTP ' . $status);
}

$result = json_decode($responseBody, true, 512, JSON_THROW_ON_ERROR);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), PHP_EOL;

Run the script in an environment where the two variables are available. For a production service, pass the decoded result to your own processing layer instead of printing it, and avoid logging the Bearer token or the entire request environment.

Inspect the same search from Python

A second client can be useful when a data engineer needs to inspect the same search outside the PHP application. This version uses Python’s standard library and reads the same environment variables.

import json
import os
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

api_key = os.environ["KLASIFY_API_KEY"]
body = os.environ["DISCOVERY_BODY"]

# Validate the supplied body before sending it.
json.loads(body)

request = Request(
    "https://www.klazify.com/api/discovery",
    data=body.encode("utf-8"),
    headers={
        "Authorization": "Bearer " + api_key,
        "Content-Type": "application/json",
    },
    method="POST",
)

try:
    with urlopen(request, timeout=30) as response:
        result = json.load(response)
except HTTPError as exc:
    raise SystemExit(f"Discovery returned HTTP {exc.code}") from exc
except URLError as exc:
    raise SystemExit(f"Discovery request failed: {exc.reason}") from exc

print(json.dumps(result, indent=2))

Once you have verified the discovery response structure for your request, extract the returned domains and any other fields your workflow needs. Keep that extraction separate from policy logic so a change in your internal taxonomy does not require rewriting the HTTP client.

Understand an individual-domain response

The following supplied example is an individual-domain categorization and enrichment response. It is useful for understanding the signals Klazify can return, but it should not be assumed to be the response to the discovery request above.


{
    "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"
    ]
}

Here, domain.categories contains category names and confidence values; one entry also contains an IAB mapping. A reporting pipeline can retain both the original category and its internal equivalent, rather than discarding the source classification after mapping.

objects.company supplies company context such as location, employee range, tags and technologies. social_media and raised are null in this example, so downstream code must tolerate missing values. The registration fields and similar domains are additional signals, not proof that a site is safe or suitable for a particular audience.

The revenue value and date-related fields should be interpreted according to the documentation before being displayed or compared. In particular, do not infer a currency or timezone from the example alone, and do not treat relative day counts in a stored response as permanently current.

Make the pipeline reliable

Control throughput. If your application runs many searches or enriches many discovered domains, use a queue and limit concurrent requests according to your account’s applicable limits. Group work in your application, but do not assume that discovery accepts a batch of independent searches in one request. Check the current documentation and account details for limits.

Cache at the right level. Cache enrichment results by normalized domain so repeated appearances in signups, ad logs or CRM records do not trigger unnecessary lookups. For discovery, cache by the complete search criteria instead: a result for one set of filters is not interchangeable with another. Record when each result was retrieved and choose a refresh policy that matches how quickly your application needs to detect changes.

Keep unknown separate from blocked. A new domain, an incomplete response or a failed request should enter an explicit unknown or review state. Whether that state is allowed temporarily or held for review is a product policy decision; it should not be silently converted into a category match.

Map categories deliberately. Maintain a versioned mapping from Klazify category names or IAB values to your own labels. Preserve the source value and confidence alongside the mapped label, and send unmapped or ambiguous entries to review. For ad-placement audits, keep the category evidence with the placement record so a reviewer can understand why it was flagged.

Klazify’s Starter plan is $39.99 per month with a seven-day trial. Failed or unreachable calls are not billed; still record failures in your own monitoring so you can retry or investigate them. For another way to connect Klazify to an application workflow, see MCP.

FAQ

Does discovery classify a URL I already have?

Discovery searches the database using filters. For a known URL or domain, use the categorization endpoint and its documented request format instead.

Can I filter a search by technology and employee count?

Discovery supports filters for technology and employees, as well as category and country. Use the documentation to construct the filter body and select accepted values.

What should I do when a domain has no usable category?

Keep it in an unknown or review state, record the lookup outcome and retry according to your refresh policy. Do not treat missing data as a positive safety or policy assessment.

Should I use the example response as my discovery schema?

No. It illustrates an individual-domain categorization response. Inspect the documented discovery response and your actual search output before implementing field extraction.

Ready to build a domain discovery workflow? Register for a free account, then configure a discovery request with the filters your application needs.

Ready to use Klazify?

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

Get Started Free