Weighting API

Data weighting directly in your pipeline. JSON in, results back.

No manual uploads. No browser. Just your own data pipeline.

Weighting That Fits Your Workflow

Our web tool is great for one-off projects, but when you need to weight data on a schedule — nightly batch jobs, automated survey pipelines, or on-demand processing triggered by your own application — you need an API.

The SampleWeighting API gives you the same Iterative Proportional Fitting (IPF) engine that powers our web tool, exposed as a single REST endpoint. Authenticate with an API key, POST a JSON payload containing your data and targets, and receive weighted results in seconds.

How It Fits Into Your Pipeline

1. Collect Data

Your survey platform, database, or data warehouse produces raw respondent data.

2. Call the API

POST your headers, data rows, and target distributions as JSON. Our engine weights the data in seconds.

3. Use the Results

Receive weighted data, summary stats, and efficiency metrics back as JSON — ready for your reporting layer.

Simple to Integrate

A single POST request is all it takes. Here's a Python example — the API also works with cURL, JavaScript, R, or any HTTP client.

Python (requests)
import requests

response = requests.post(
    "https://app.sampleweighting.com/api/weight",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type":  "application/json",
    },
    json={
        "name": "Q3 Survey Batch",
        "headers": ["id", "gender", "age_group", "region", "satisfaction"],
        "targets": {
            "gender":    {"Male": 0.49, "Female": 0.51},
            "age_group": {"18-34": 0.30, "35-54": 0.40, "55+": 0.30},
        },
        "data": [
            [1, "Male",   "18-34", "West",  4],
            [2, "Female", "35-54", "East",  5],
            [3, "Male",   "55+",   "South", 3],
            # ... your full dataset
        ],
        "options": {
            "max_iterations": 200,
            "max_factor": 5
        }
    }
)

result = response.json()
print(result["summary"])      # efficiency, design effect, etc.
print(result["weighted_data"]) # your weighted results

What You Get

Fast Processing

Results returned in seconds, even for large datasets. The same proven IPF engine used by our web tool.

API Key Auth

Secure Bearer token authentication. Generate and manage keys from your dashboard.

Configurable Options

Control max iterations, set weight caps, and specify population size — or use sensible defaults.

Rich Responses

Get weighted data plus summary stats — weighting efficiency, design effect, and per-variable convergence details.

Same Credit System

Uses the same credits as the web tool. One credit per successful weighting run. No separate API pricing.

Validation Built In

Clear error messages when something is off — mismatched columns, invalid targets, or missing fields. No guesswork.

Full Run History in Your Dashboard

Every API call is logged in your web dashboard with its status, timestamp, and results. If your pipeline had a hiccup — say the weighting ran successfully but a downstream step failed — you can go back, review the run, and re-download the weighted data as an Excel spreadsheet. No need to re-run the job or spend another credit.

It's the safety net that makes automated weighting practical: fire-and-forget when things go right, full visibility when they don't.

Built for Automation

Nightly Batch Processing

Schedule a cron job or cloud function that pulls the latest survey responses, sends them to the API, and stores weighted results — ready for morning reports.

Survey Platform Integration

Wire up a webhook from your survey tool so that weighting runs automatically every time a fieldwork batch closes.

Internal Tools & Dashboards

Embed weighting into your own application. Let your team trigger a weighting run from a button click without ever leaving your internal platform.

Multi-Market Studies

Loop through datasets for each market, apply country-specific targets, and collect all weighted results in one script run.

Request Structure at a Glance

FieldRequiredDescription
headersYesOrdered list of column names. Every data row must match this length.
dataYesArray of respondent rows. Can include columns not used in targets.
targetsYesWeight targets per variable. Values must sum to 1.0 and be greater than zero.
nameNoOptional project label. Auto-generated if omitted.
optionsNoFine-tuning: max_iterations, max_factor (weight cap), and population size.

Full request/response schemas and code examples in cURL, Python, and JavaScript are available in the API Documentation inside your dashboard.

Getting Started

  1. 1Sign up for a SampleWeighting account and purchase a credit package.
  2. 2Enable API access in your workspace settings and generate an API key.
  3. 3Make your first call using the code examples in the dashboard's API Documentation page.

Get your free trial now!

With just a few clicks, you'll have access to our wonderful weighting tool. Let us make it easy for you.

Get your free trial
Professional smiling