Data weighting directly in your pipeline. JSON in, results back.
No manual uploads. No browser. Just your own data pipeline.
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.
Your survey platform, database, or data warehouse produces raw respondent data.
POST your headers, data rows, and target distributions as JSON. Our engine weights the data in seconds.
Receive weighted data, summary stats, and efficiency metrics back as JSON — ready for your reporting layer.
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.
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 resultsResults returned in seconds, even for large datasets. The same proven IPF engine used by our web tool.
Secure Bearer token authentication. Generate and manage keys from your dashboard.
Control max iterations, set weight caps, and specify population size — or use sensible defaults.
Get weighted data plus summary stats — weighting efficiency, design effect, and per-variable convergence details.
Uses the same credits as the web tool. One credit per successful weighting run. No separate API pricing.
Clear error messages when something is off — mismatched columns, invalid targets, or missing fields. No guesswork.
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.
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.
Wire up a webhook from your survey tool so that weighting runs automatically every time a fieldwork batch closes.
Embed weighting into your own application. Let your team trigger a weighting run from a button click without ever leaving your internal platform.
Loop through datasets for each market, apply country-specific targets, and collect all weighted results in one script run.
| Field | Required | Description |
|---|---|---|
| headers | Yes | Ordered list of column names. Every data row must match this length. |
| data | Yes | Array of respondent rows. Can include columns not used in targets. |
| targets | Yes | Weight targets per variable. Values must sum to 1.0 and be greater than zero. |
| name | No | Optional project label. Auto-generated if omitted. |
| options | No | Fine-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.
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
