Integrate the Competitive Intelligence API in PHP

December 02, 2026
Integrate the Competitive Intelligence API in PHP

You want to compare a competitor’s web presence without manually collecting traffic and category data for every domain. By the end of this guide, you can call Klazify’s traffic intelligence endpoint from PHP, extract the returned signals, and use categorization data to organize domains for competitive analysis.

Why use domain intelligence for competitive research?

Documentation describes Klazify as a source of domain data that can support both traffic analysis and website classification. For a competitive intelligence workflow, these are complementary: traffic signals help you investigate a domain’s reach, while categories help you decide which domains belong in the same comparison group.

Illustration: Integrate the Competitive Intelligence API in PHP

Klazify analyzes website content for classification rather than relying only on a domain name. Its hierarchical system includes IAB taxonomy mapping, which can help an ad-tech team group sites consistently, and its company and similar-domain data can add context to a research list. These capabilities are useful when a domain’s name alone does not make its market position clear.

Classification is not proof that two businesses compete directly, and a category alone does not establish compliance or brand safety. Use the response to build a candidate set, then apply your own rules and review process. For example, a site classified under consumer electronics might belong in a market research group, but it should not automatically be treated as a direct competitor.

Send a traffic intelligence request

The traffic intelligence endpoint accepts a JSON body containing a URL. Replace YOUR_API_KEY with your key and run this request from a terminal:

curl --request POST \
  --url https://www.klazify.com/api/domain_traffic_intelligence \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"url":"https://cbsnews.com"}'

The traffic signals to inspect include global_rank, country_rank, category_rank, monthly_visits, engagement, traffic_sources, and top_countries. Check the documentation for the response structure, definitions, time periods, and units before comparing or displaying values.

Field Competitive intelligence use Implementation consideration
global_rank, country_rank, category_rank Compare ranking signals across a selected set of domains. Keep each rank’s scope separate; confirm its definition before sorting or labeling it.
monthly_visits Examine a traffic-volume signal alongside other domains. Record the applicable reporting period and refresh time.
engagement Add engagement context to a traffic comparison. Interpret the contained values using their documented definitions and units.
traffic_sources Investigate how traffic reaches a domain. Preserve source detail rather than collapsing it into an undocumented score.
top_countries Understand the geographic context of an audience. Check the returned structure before mapping countries into your reporting model.

Integrate the request in PHP

The following script takes the target URL as a command-line argument and reads the API key from the KLazify_API_KEY environment variable. It uses PHP’s cURL extension and searches the decoded response for the traffic fields above, preserving their values rather than assuming a particular nested structure.

<?php

$apiKey = getenv('KLazify_API_KEY');
$url = $argv[1] ?? null;

if (!$apiKey || !$url) {
    fwrite(STDERR, "Set KLazify_API_KEY and pass a URL as an argument.\n");
    exit(1);
}

$body = json_encode(['url' => $url], JSON_THROW_ON_ERROR);

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

$response = curl_exec($handle);

if ($response === false) {
    $message = curl_error($handle);
    curl_close($handle);
    fwrite(STDERR, "Request failed: " . $message . "\n");
    exit(1);
}

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

if ($status < 200 || $status >= 300) {
    fwrite(STDERR, "HTTP request failed with status " . $status . "\n");
    exit(1);
}

try {
    $data = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
    fwrite(STDERR, "Response was not valid JSON.\n");
    exit(1);
}

$wanted = [
    'global_rank',
    'country_rank',
    'category_rank',
    'monthly_visits',
    'engagement',
    'traffic_sources',
    'top_countries',
];

function findFields($node, $wanted, $path = '')
{
    $found = [];

    if (!is_array($node)) {
        return $found;
    }

    foreach ($node as $key => $value) {
        $currentPath = $path === '' ? (string) $key : $path . '.' . $key;

        if (in_array($key, $wanted, true)) {
            $found[$currentPath] = $value;
        }

        if (is_array($value)) {
            $found = array_merge(
                $found,
                findFields($value, $wanted, $currentPath)
            );
        }
    }

    return $found;
}

$fields = findFields($data, $wanted);
echo json_encode($fields, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";

Run the script with your own target URL as its argument. The output keys show where matching fields were found, so you can inspect the response before defining a stable mapping for your application. An empty result means no matching fields were found; it should not be interpreted as zero traffic.

For production use, validate the target URL before submitting it, protect the key in your deployment’s secret store, and log failures without logging the authorization header. The example exits on transport, HTTP, and JSON errors; your worker can instead place failed jobs into a controlled retry or review queue.

JavaScript alternative for a pipeline worker

If another part of your pipeline uses JavaScript, the same endpoint can be called with fetch. This example also takes a URL from the command line and reads the key from the environment. It requires a JavaScript runtime with built-in fetch.

const apiKey = process.env.KLAZIFY_API_KEY;
const url = process.argv[2];

if (!apiKey || !url) {
  throw new Error("Set KLAZIFY_API_KEY and pass a URL as an argument.");
}

const response = await fetch(
  "https://www.klazify.com/api/domain_traffic_intelligence",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ url }),
  }
);

if (!response.ok) {
  throw new Error(`HTTP request failed with status ${response.status}`);
}

const data = await response.json();
const wanted = new Set([
  "global_rank",
  "country_rank",
  "category_rank",
  "monthly_visits",
  "engagement",
  "traffic_sources",
  "top_countries",
]);

function findFields(node, path = "", found = {}) {
  if (node === null || typeof node !== "object") return found;

  for (const [key, value] of Object.entries(node)) {
    const currentPath = path ? `${path}.${key}` : key;
    if (wanted.has(key)) found[currentPath] = value;
    findFields(value, currentPath, found);
  }

  return found;
}

console.log(JSON.stringify(findFields(data), null, 2));

Both examples deliberately retain the returned value at each matching path. Once you have verified the documented traffic response shape, replace the recursive inspection with explicit field mapping and validation appropriate to your data store.

Use classification to build a comparison group

Traffic intelligence and categorization answer different questions. The former supplies traffic-related signals; the latter helps identify what a website is about. Klazify’s categorization endpoint is https://www.klazify.com/api/categorize, and the following is an example categorization response. It is not an example response from the traffic intelligence 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"
    ]
}

For comparison grouping, start with domain.categories. Each category has a name and confidence; the first also includes an IAB mapping. The two entries in this example can support a rule that assigns a domain to a consumer-electronics research group, while retaining the mobile-phones classification as additional context.

Keep the original category path and confidence alongside your internal label. Your taxonomy might combine several Klazify paths into one research group or route lower-confidence matches to review. Choose thresholds based on your own validation rather than treating the example confidence values as a guaranteed accuracy rate.

objects.company provides context such as the company name, location, employee range, tags, and technologies. Treat missing values such as social_media: null and raised: null as unknown, not as evidence that no account or funding exists. Confirm the definitions and currency of financial fields before using them in a report.

similar_domains can seed a research queue, but review each candidate before labeling it a competitor. Registration data can provide domain context; it should not be used by itself to judge a business’s age or the safety of its website. The logo URL is presentation data, not a classification or traffic signal.

Operate the integration at scale

Normalize inputs before queuing requests: use a consistent domain key for your cache, while retaining the submitted URL when page-level context matters. Avoid merging distinct pages into a domain-level cache entry if your application depends on URL-level classification.

Cache successful results per domain with a retrieval timestamp and a refresh policy suited to the decision. A research dashboard can tolerate older data differently from an ad-placement audit. Store the original response or the fields needed for reprocessing, along with your internal mapping version, so taxonomy changes do not require an immediate API call for every record.

For large lists, submit individual requests through a bounded worker queue rather than launching all requests at once. Check your plan’s current rate limits in the documentation, control concurrency, and back off when requests are throttled or temporarily fail. This avoids assuming that the endpoint accepts a bulk payload or that every account has the same limits.

Separate unknown data from negative results. A new or unreachable domain may need a later retry or manual review; a missing category should not automatically become a block, a competitor match, or a zero-valued metric. Keep error states and successful responses distinguishable in your database.

When mapping categories, maintain an explicit table from returned paths or IAB mappings to your organization’s labels. Test it against representative domains, monitor unmapped paths, and review changes before using the mapping for automatic filtering. A content category is useful context for an audit, but it is not a standalone cybersecurity verdict.

Klazify also offers MCP for teams exploring another integration route. The PHP request above remains a direct REST integration and can be used independently of that option.

FAQ

Can I use the same request for categorization and traffic intelligence?

The examples serve different endpoints. Use the traffic intelligence request for traffic signals, and consult the categorization documentation when you need category and company data. Do not assume the two responses share the same structure.

How should I handle a domain with no usable result?

Record it as unknown or unavailable, retain the failure context, and retry or review it according to your workflow. Do not substitute zero traffic or infer that the domain belongs outside your comparison group.

Are failed requests billed?

Failed or unreachable calls are not billed. Still track failures operationally so a broken integration does not leave your research dataset incomplete.

What does it cost to get started?

The Starter plan is $39.99 per month with a 7-day trial. Check the current plan details and applicable limits before sizing a production workload.

Ready to test the workflow with your own domains? Register for a free account, obtain your API key, and start with a small set of domains you can validate before scaling the queue.

Ready to use Klazify?

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

Get Started Free