Domain Social Media API in Python: Company Social Profiles

October 05, 2026
Domain Social Media API in Python: Company Social Profiles

You’re building a signup enrichment, a brand-safety crawler, or a CRM workflow and you need to pull the official social profiles for each domain. By the end of this guide, you’ll POST a website to the Klazify Domain Social Media endpoint from Python, read the returned social URLs (for example, facebook_url and twitter_url), and save them reliably into your pipeline.

What the Domain Social Media endpoint does

The Domain Social Media API extracts public profile URLs for a given website. You send a URL (or domain), and the API responds with the social handles it can validate for that site. This is useful when you want to:

  • Enrich a signup: add verified social links to a company record.
  • Improve targeting: match domains from your ad inventory to their social presence.
  • Automate QA: check whether a partner site lists the required profiles.
  • Build a safer crawler: only allowlisted social domains go downstream.

This post focuses on the Klazify POST /api/domain_social_media endpoint and shows how to call it in Python, interpret the response, cache results, and harden your integration for scale. You can explore the broader platform at klazify.com and check the API reference in the Documentation.

Quick start: go live in four steps

  1. Register (7-day trial): Register
  2. Copy your Bearer key from the dashboard.
  3. POST /api/domain_social_media.
  4. Store facebook_url and twitter_url when present.

The Starter plan is $39.99/mo with a 7-day trial, and failed calls are not billed. If you’re integrating across multiple environments or coordinating keys for several services, visit the MCP to manage access consistently.

Official sample request and response

The official sample below posts the CBS News homepage URL and returns the site’s public social profile URLs. This is a live format example you can adapt to your own domains.

curl -X POST "https://www.klazify.com/api/domain_social_media" -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"url":"https://cbsnews.com"}'

Here is the official JSON response format for that request:

{
  "domain": {
    "domain_url": "https://cbsnews.com",
    "social_media": {
      "facebook_url": "https://facebook.com/CBSNews",
      "twitter_url": "https://twitter.com/CBSNews",
      "instagram_url": "https://instagram.com/cbsnews",
      "youtube_url": "https://youtube.com/CBSNews",
      "linkedin_url": null
    }
  }
}

Note on samples: the example uses https://cbsnews.com dated 2026-03-10. You can swap in any URL or domain you need to enrich; the API behavior is the same.

Python example: read and store facebook_url and twitter_url

The snippet below sends the same request in Python, parses the JSON, and saves the most-used fields when present. Replace YOUR_API_KEY with the Bearer token from your account.

import json
import os
import time
import requests

API_KEY = os.getenv("KLAZIFY_API_KEY", "YOUR_API_KEY")
ENDPOINT = "https://www.klazify.com/api/domain_social_media"

def normalize_domain(url_or_domain: str) -> str:
    # Cache key normalization helps deduplicate requests to the same site.
    # Keep it simple: lowercase and strip trailing slashes.
    return url_or_domain.strip().lower().rstrip("/")

def fetch_social_urls(url_or_domain: str) -> dict:
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
        "Accept": "application/json",
    }
    payload = {"url": url_or_domain}

    resp = requests.post(ENDPOINT, headers=headers, json=payload, timeout=20)
    # A non-2xx status should be retried depending on your policy.
    resp.raise_for_status()
    data = resp.json()

    # Handle explicit API-level failures.
    if isinstance(data, dict) and data.get("success") is False:
        # Failed calls are not billed; log and return an empty result.
        return {"success": False, "error": data.get("error")}

    # Only copy fields when they're present.
    out = {"success": True}
    for field in ("facebook_url", "twitter_url"):
        if field in data and data[field]:
            out[field] = data[field]

    return out

# Example usage: CBS News official sample URL
domain = "https://cbsnews.com"
key = normalize_domain(domain)

# Optional: a trivial in-memory cache for repeated lookups
CACHE = {}
cached = CACHE.get(key)
if cached:
    result = cached
else:
    result = fetch_social_urls(domain)
    # Cache for a day (tune this to your update needs)
    CACHE[key] = result
    CACHE[key + ":ts"] = int(time.time())

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

If you prefer a drop-in recipe to get started, sign up and copy your key: Read social URLs in Python → Register.

Interpreting the response

The JSON returned by POST /api/domain_social_media contains the public profile URLs that Klazify can validate for the submitted site. For many teams, the immediately actionable fields are:

  • facebook_url: the official Facebook Page URL for the site, when available.
  • twitter_url: the official profile URL on Twitter/X for the site, when available.

Use simple null checks before writing values to your database. In your enrichment or ETL job, a practical pattern is:

  • If success is false, log the error message and skip billing-sensitive retries (failed calls are not billed).
  • If success is true but a profile field is missing, treat it as “unknown” rather than “no profile.” Some sites do not operate every social network.

When ingesting into a CRM, store each URL as its own field and avoid attempting to parse usernames from the URL unless your downstream systems need that transformation. Storing the full URL preserves reversibility and is the most portable across vendors and UI layers.

End-to-end workflow: from domain to downstream systems

1) Input normalization

Domains and URLs appear in varied forms (with or without scheme, with www, with trailing slashes). Normalize consistently to reduce duplicate work and enable effective caching:

  • Lowercase the input.
  • Trim whitespace and trailing slashes.
  • Consider canonicalizing to a registrable domain for caching if your use case is domain-level.

2) Request construction

POST to /api/domain_social_media with your Authorization: Bearer key. If you’re queuing many lookups, keep request bodies small and avoid unnecessary retries. For official parameters and accepted payload structure, consult the Documentation.

3) Response handling

  • Check for success=false and short-circuit if present.
  • Read available social URL fields (for example, facebook_url and twitter_url) and store them as-is.
  • Leave fields you don’t use untouched to keep your schema lean.

4) Caching and freshness

Social handles rarely change, so caching at the domain level pays off. A common approach:

  • Cache per normalized domain key.
  • Use a TTL tuned to your SLA and data volume. Many teams refresh on the order of days to weeks depending on how frequently they expect profiles to change.
  • Invalidate on demand for critical partners or during migrations.

When caching, also store a lightweight metadata object with the timestamp of last fetch. That makes telemetry and re-crawling schedules straightforward in your data pipeline.

5) Error strategy and retries

  • Treat transport or 5xx errors with exponential backoff and jitter.
  • Do not hard-fail your job because a social profile is temporarily unavailable; store a partial result and retry later.
  • If the API returns success=false, record the error message and move on. Failed calls are not billed.

6) Schema design and mapping

Map returned fields into your schema with explicit nullability. Example approaches:

  • crm_accounts.facebook_url, crm_accounts.twitter_url: nullable string columns.
  • enrichment.social: a JSON blob kept in your warehouse for future reprocessing.
  • Feature flags: add an is_social_verified boolean in your model if your UI distinguishes verified vs. missing links.

If you maintain your own taxonomy of fields or need to collapse multiple sources into a single “social” object, write a mapper that accepts the API response and outputs your canonical structure. Keep the raw response alongside your mapped fields for auditability.

Operational guidance for scale

Batching

The endpoint processes one site per POST request. To scale, run concurrent workers that each pull from a domain queue and POST independently. A simple distributed queue (e.g., your job system of choice) plus horizontal workers is easy to reason about and fault-tolerant.

Throughput and limits

Design your client to respect backpressure. If you observe throttling or timeouts, slow the queue or increase backoff. For plan-specific limits or advanced behaviors, refer to the Documentation.

Idempotency

Repeatedly posting the same normalized domain should be safe, but avoid unnecessary duplicate calls by caching and de-duplicating your input list before sending requests.

Handling unknown or new domains

Some sites will not expose profiles, or they might be too new to extract. In that case:

  • Persist a partial record with whatever fields are present.
  • Queue a recheck after a longer delay (e.g., days) rather than hammering the endpoint.
  • Expose a “missing social” status in your internal dashboards to track enrichment coverage without blocking business workflows.

Putting the results to work

Once you have social URLs, plug them into your downstream systems:

  • CRM enrichment: update or create account records with the URLs so Sales and CS have verified links.
  • Ad tech and brand safety: diff discovered handles against your allowlist/denylist before approving inventory.
  • Analytics: attribute social reach by joining profile URLs to your data mart of engagement metrics.

If your product sends users to social profiles, prefer opening these full URLs rather than reconstructing them from usernames. This reduces user-facing errors and drift when platforms change their URL conventions.

Testing and monitoring

  • Golden test set: keep a small set of known domains and expected profile URLs. Run this set in CI to catch regressions in your mapping code.
  • Telemetry: log domain, status (success/partial/failure), and count of non-empty social fields per request.
  • Alerts: set thresholds on failure ratios over rolling windows to detect upstream or network incidents early.

For further details about payloads and behaviors, head to the Documentation. You can always return to the dashboard at klazify.com to rotate keys and view usage.

Security and compliance notes

  • Store the Bearer token in your secret manager; never commit keys to source control.
  • Separate read/write roles if multiple services call the API.
  • Log only what you need. If logs include response bodies, ensure they follow your data retention policy.

Cost awareness

The Starter plan is $39.99/mo with a 7-day trial. Since failed calls are not billed, use response-level checks to detect success=false and avoid retry storms. Cache aggressive lookups to reduce duplicate requests and keep your usage predictable. You can register and get your key here: Register.

FAQ

What should I do if the response has success=false?
Log the error message, skip further retries for that item, and proceed. Failed calls are not billed, so you can safely record the failure and requeue for a later pass if appropriate.

How do I avoid duplicate requests for the same site?
Normalize inputs (lowercase, trim trailing slashes) and cache results per normalized domain. De-duplicate your input list before posting.

What if a social URL field is missing?
Treat it as unknown rather than “no account.” Many sites do not operate every social platform. Store null and move on; you can refresh on a longer schedule.

Can I run this in batches?
Yes. Send one POST per site and run multiple workers concurrently. Use backoff and respect backpressure if you observe throttling. Check the Documentation for plan behaviors.

Where can I manage my API keys and monitor usage?
Use your account dashboard at klazify.com. If you coordinate multiple environments or services, see the MCP.

Ready to enrich domains with verified social profiles? Create a free account to start your 7-day trial, grab your Bearer key, and ship your first POST request in minutes: Register.

Ready to use Klazify?

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

Get Started Free