API
Campaign API
With the Campaign API your software runs campaigns exactly like the dashboard. The same checks, the same halal rules, the same money handling — and a HalalAdz person reviews every campaign and every ad. The API can never skip that review.
The whole flow
POST /campaigns— make a draft campaign with its goal, platforms and count; the answer has the price.POST /uploads→ PUT the file →POST /campaigns/{id}/creatives— add the ads.POST /campaigns/{id}/launch— the whole budget is set aside for the campaign in one step and the campaign goes to halal review (in_review).- When a HalalAdz reviewer approves it, the
campaign.approvedwebhook arrives and the ads start; if rejected you getcampaign.rejected(with the reason) and the money goes back. POST /campaigns/{id}/pause,/resume— pause and resume.POST /campaigns/{id}/end— ends for good; the budget not spent goes back at once.
| Request (scope) | What it does |
|---|---|
GET /campaignsread / campaigns:write | List campaigns (newest first) |
GET /campaigns/{id}read / campaigns:write | One campaign |
POST /campaignscampaigns:write | Create a draft campaign |
PATCH /campaigns/{id}campaigns:write | Change budget, dates and name (before launch) |
POST /quotescampaigns:write | Get a price — nothing is saved |
POST /campaigns/{id}/launchcampaigns:write | Pay the budget and send to review (same as /submit) |
POST /campaigns/{id}/pause, /resumecampaigns:write | Pause, resume |
POST /campaigns/{id}/endcampaigns:write | End, unspent budget back |
GET /campaigns/{id}/creativesread / creatives:write | List ads and their review status |
POST /uploadscreatives:write | An upload address for a picture or video |
POST /campaigns/{id}/creativescreatives:write | Add an ad — always goes to human review |
1. Create a campaign
POST /campaigns
The same details as "New campaign" in the dashboard: name, goal (brand, orders, installs, video, members), business category, halalConfirmed: true, platforms, how many results you want (targetUnits) or a budget (budgetMicros), when it starts and how many hours it runs, and the countries. A category that is not halal or not allowed answers 422 — as in the dashboard. The campaign starts as a draft; no money moves.
curl -X POST https://api.halaladz.com/api/v1/campaigns \
-H "Authorization: Bearer $HALALADZ_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "name": "Eid dates offer", "goal": "orders", "declaredCategory": "food", "halalConfirmed": true, "platforms": ["website", "app"], "targetUnits": "200", "startMode": "after_review", "durationHours": 168, "targeting": { "countries": ["BD", "MY", "GB"] } }'import { randomUUID } from "node:crypto";
const res = await fetch("https://api.halaladz.com/api/v1/campaigns", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.HALALADZ_KEY}`,
"Idempotency-Key": randomUUID(), // keep it, and send the SAME value if you retry
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Eid dates offer",
goal: "orders",
declaredCategory: "food",
halalConfirmed: true,
platforms: ["website", "app"],
targetUnits: "200",
startMode: "after_review",
durationHours: 168,
targeting: { countries: ["BD", "MY", "GB"] },
}),
});
const campaign = await res.json();
if (!res.ok) throw new Error(`${res.status} ${campaign.error}: ${campaign.message}`);
console.log(campaign.id, campaign.status, campaign.totalMicros); // a draft, and its price<?php
$body = [
'name' => 'Eid dates offer',
'goal' => 'orders',
'declaredCategory' => 'food',
'halalConfirmed' => true,
'platforms' => ['website', 'app'],
'targetUnits' => '200',
'startMode' => 'after_review',
'durationHours' => 168,
'targeting' => ['countries' => ['BD', 'MY', 'GB']],
];
$ch = curl_init('https://api.halaladz.com/api/v1/campaigns');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('HALALADZ_KEY'),
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($body),
CURLOPT_RETURNTRANSFER => true,
]);
$campaign = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $campaign['id'], ' ', $campaign['totalMicros'];import os, uuid
import requests
KEY = os.environ["HALALADZ_KEY"]
r = requests.post(
"https://api.halaladz.com/api/v1/campaigns",
headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())},
json={
"name": "Eid dates offer",
"goal": "orders",
"declaredCategory": "food",
"halalConfirmed": True,
"platforms": ["website", "app"],
"targetUnits": "200",
"startMode": "after_review",
"durationHours": 168,
"targeting": {"countries": ["BD", "MY", "GB"]},
},
timeout=30,
)
r.raise_for_status()
campaign = r.json()
print(campaign["id"], campaign["totalMicros"]){
"id": 123,
"status": "draft",
"goal": "orders",
"platforms": ["website", "app"],
"targetUnits": "200",
"totalMicros": "3000000000",
"quote": { "totalMicros": "3000000000", "unitPriceMicros": "15000000", "quoteKey": "q_7f3a…" }
}Change budget and dates
PATCH /campaigns/{id}
Send only what changes: targetUnits or budgetMicros, platforms, startMode, startAt, durationHours, name. The price is worked out again and comes in the answer. Budget and dates can change only until you launch — as in the dashboard, once launched the budget is paid and locked (409 budget_locked). To run more, create a new campaign.
curl -X PATCH https://api.halaladz.com/api/v1/campaigns/123 \
-H "Authorization: Bearer $HALALADZ_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"targetUnits": "300", "startMode": "date", "startAt": "2026-12-20T09:00:00+06:00", "durationHours": 240}'import { randomUUID } from "node:crypto";
const res = await fetch("https://api.halaladz.com/api/v1/campaigns/123", {
method: "PATCH",
headers: {
Authorization: `Bearer ${process.env.HALALADZ_KEY}`,
"Idempotency-Key": randomUUID(),
"Content-Type": "application/json",
},
// only what changes; the rest stays as it is
body: JSON.stringify({ targetUnits: "300", startMode: "date", startAt: "2026-12-20T09:00:00+06:00", durationHours: 240 }),
});
const updated = await res.json(); // updated.totalMicros = the new price<?php
$ch = curl_init('https://api.halaladz.com/api/v1/campaigns/123');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('HALALADZ_KEY'),
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['targetUnits' => '300', 'startMode' => 'date', 'startAt' => '2026-12-20T09:00:00+06:00', 'durationHours' => 240]),
CURLOPT_RETURNTRANSFER => true,
]);
$updated = json_decode(curl_exec($ch), true);
echo $updated['totalMicros'];import os, uuid
import requests
r = requests.patch(
"https://api.halaladz.com/api/v1/campaigns/123",
headers={"Authorization": f"Bearer {os.environ['HALALADZ_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
json={"targetUnits": "300", "startMode": "date", "startAt": "2026-12-20T09:00:00+06:00", "durationHours": 240},
timeout=30,
)
print(r.status_code, r.json().get("totalMicros"))2. Add ads
POST /uploads
POST /campaigns/{id}/creatives
First get an upload address, PUT the file to uploadUrl with exactly the headers in the answer, then add the ad with its assetUrl. Every new ad starts as pending (ai_passed only if an optional automatic pre-check ran; today every ad is checked by a person) — never straight to approved. When a HalalAdz person approves it you get the creative.approved webhook, when rejected creative.rejected. Links to blocked domains are refused at once.
# 1. ask for an upload address
curl -X POST https://api.halaladz.com/api/v1/uploads \
-H "Authorization: Bearer $HALALADZ_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"contentType": "image/png", "sizeBytes": 48210}'
# 2. PUT the file to uploadUrl with exactly the headers in the answer
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" --data-binary @banner.png
# 3. add the ad to the campaign (it goes to the halal review)
curl -X POST https://api.halaladz.com/api/v1/campaigns/123/creatives \
-H "Authorization: Bearer $HALALADZ_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"format": "banner_300x250", "assetUrl": "'"$ASSET_URL"'", "landingUrl": "https://shop.example.com/eid"}'import { randomUUID } from "node:crypto";
import { readFile, stat } from "node:fs/promises";
const H = { Authorization: `Bearer ${process.env.HALALADZ_KEY}`, "Content-Type": "application/json" };
const file = "banner.png";
const up = await (await fetch("https://api.halaladz.com/api/v1/uploads", {
method: "POST",
headers: { ...H, "Idempotency-Key": randomUUID() },
body: JSON.stringify({ contentType: "image/png", sizeBytes: (await stat(file)).size }),
})).json();
await fetch(up.uploadUrl, { method: "PUT", headers: up.headers, body: await readFile(file) });
const ad = await (await fetch("https://api.halaladz.com/api/v1/campaigns/123/creatives", {
method: "POST",
headers: { ...H, "Idempotency-Key": randomUUID() },
body: JSON.stringify({ format: "banner_300x250", assetUrl: up.assetUrl, landingUrl: "https://shop.example.com/eid" }),
})).json();
console.log(ad.id, ad.reviewStatus); // "pending" — a HalalAdz person reviews it<?php
function hz(string $method, string $path, array $body) {
$ch = curl_init('https://api.halaladz.com/api/v1' . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('HALALADZ_KEY'),
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($body),
CURLOPT_RETURNTRANSFER => true,
]);
$out = json_decode(curl_exec($ch), true);
curl_close($ch);
return $out;
}
$file = 'banner.png';
$up = hz('POST', '/uploads', ['contentType' => 'image/png', 'sizeBytes' => filesize($file)]);
$put = curl_init($up['uploadUrl']);
$headers = [];
foreach ($up['headers'] as $k => $v) { $headers[] = "$k: $v"; }
curl_setopt_array($put, [CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => $headers, CURLOPT_POSTFIELDS => file_get_contents($file), CURLOPT_RETURNTRANSFER => true]);
curl_exec($put);
$ad = hz('POST', '/campaigns/123/creatives', ['format' => 'banner_300x250', 'assetUrl' => $up['assetUrl'], 'landingUrl' => 'https://shop.example.com/eid']);
echo $ad['reviewStatus']; // pendingimport os, uuid
import requests
API = "https://api.halaladz.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['HALALADZ_KEY']}"}
def idem():
return {**H, "Idempotency-Key": str(uuid.uuid4())}
data = open("banner.png", "rb").read()
up = requests.post(f"{API}/uploads", headers=idem(), json={"contentType": "image/png", "sizeBytes": len(data)}, timeout=30).json()
requests.put(up["uploadUrl"], headers=up["headers"], data=data, timeout=60).raise_for_status()
ad = requests.post(
f"{API}/campaigns/123/creatives",
headers=idem(),
json={"format": "banner_300x250", "assetUrl": up["assetUrl"], "landingUrl": "https://shop.example.com/eid"},
timeout=30,
).json()
print(ad["id"], ad["reviewStatus"]) # pending3. Launch (budget + review)
POST /campaigns/{id}/launch
Send the total you saw as expectedTotalMicros. One transaction sets the whole budget aside for the campaign and it becomes in_review. If the price changed meanwhile you get 409 price_changed (the new price in details.totalMicros) — check it and send again. Not enough money: 402 insufficient_funds; no ads yet: 422 no_creatives.
# expectedTotalMicros = the totalMicros you got when you created (or quoted) the campaign
curl -X POST https://api.halaladz.com/api/v1/campaigns/123/launch \
-H "Authorization: Bearer $HALALADZ_KEY" \
-H "Idempotency-Key: launch-123-1" \
-H "Content-Type: application/json" \
-d '{"expectedTotalMicros": "3000000000"}'const res = await fetch("https://api.halaladz.com/api/v1/campaigns/123/launch", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.HALALADZ_KEY}`,
"Idempotency-Key": "launch-123-1", // a retry with the same key never pays twice
"Content-Type": "application/json",
},
body: JSON.stringify({ expectedTotalMicros: campaign.totalMicros }),
});
const out = await res.json();
if (res.status === 409 && out.error === "price_changed") console.log("new total:", out.details.totalMicros);
else if (!res.ok) throw new Error(`${res.status} ${out.error}`);
else console.log(out.status); // "in_review"<?php
$ch = curl_init('https://api.halaladz.com/api/v1/campaigns/123/launch');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('HALALADZ_KEY'),
'Idempotency-Key: launch-123-1',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['expectedTotalMicros' => '3000000000']),
CURLOPT_RETURNTRANSFER => true,
]);
$out = json_decode(curl_exec($ch), true);
echo $out['status'] ?? $out['error']; // in_reviewimport os
import requests
r = requests.post(
"https://api.halaladz.com/api/v1/campaigns/123/launch",
headers={"Authorization": f"Bearer {os.environ['HALALADZ_KEY']}", "Idempotency-Key": "launch-123-1"},
json={"expectedTotalMicros": "3000000000"},
timeout=30,
)
out = r.json()
print(r.status_code, out.get("status") or out.get("error")) # 200 in_review4. Pause, resume, end
POST /campaigns/{id}/pause
POST /campaigns/{id}/resume
POST /campaigns/{id}/end
An active campaign pauses, a paused one resumes; the wrong state answers 409 invalid_status. end is for good — the unspent budget goes back at once, and it cannot be undone. Whatever paused it (you, HalalAdz, or money running out) you get the campaign.paused webhook; when the whole budget is used, campaign.budget_spent.
curl -X POST https://api.halaladz.com/api/v1/campaigns/123/pause \
-H "Authorization: Bearer $HALALADZ_KEY" -H "Idempotency-Key: $(uuidgen)"
curl -X POST https://api.halaladz.com/api/v1/campaigns/123/resume \
-H "Authorization: Bearer $HALALADZ_KEY" -H "Idempotency-Key: $(uuidgen)"
# for good: the unspent budget goes back at once
curl -X POST https://api.halaladz.com/api/v1/campaigns/123/end \
-H "Authorization: Bearer $HALALADZ_KEY" -H "Idempotency-Key: $(uuidgen)"import { randomUUID } from "node:crypto";
async function act(id, action) { // action: "pause" | "resume" | "end"
const res = await fetch(`https://api.halaladz.com/api/v1/campaigns/${id}/${action}`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.HALALADZ_KEY}`, "Idempotency-Key": randomUUID() },
});
const body = await res.json();
if (!res.ok) throw new Error(`${res.status} ${body.error}: ${body.message}`);
return body.status;
}
console.log(await act(123, "pause")); // "paused"<?php
function act(int $id, string $action) { // pause | resume | end
$ch = curl_init("https://api.halaladz.com/api/v1/campaigns/$id/$action");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('HALALADZ_KEY'), 'Idempotency-Key: ' . bin2hex(random_bytes(16))],
CURLOPT_RETURNTRANSFER => true,
]);
return json_decode(curl_exec($ch), true);
}
echo act(123, 'pause')['status']; // pausedimport os, uuid
import requests
def act(campaign_id, action): # "pause" | "resume" | "end"
r = requests.post(
f"https://api.halaladz.com/api/v1/campaigns/{campaign_id}/{action}",
headers={"Authorization": f"Bearer {os.environ['HALALADZ_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
timeout=30,
)
r.raise_for_status()
return r.json()["status"]
print(act(123, "pause")) # pausedIdempotency-Key: never twice
Every POST, PATCH and DELETE must carry an Idempotency-Key header (else 400 idempotency_key_required). Use a new value (e.g. a UUID) per action, and send the same value when you retry after a network error: for 24 hours the same key with the same request gets the first answer back (Idempotent-Replayed: true) — so no campaign is made twice and no budget is paid twice. The same key with a different request answers 422 idempotency_key_reused; while the first is still running, 409 idempotency_in_progress.
Live keys: the switch and the daily spend limit
- To keep real money safe, write access on live keys (
campaigns:write,creatives:write) stays off until HalalAdz turns it on. While it is off, making such a key answers422 campaign_write_offand a write request with an older key403 campaign_write_off. Test keys always have it. - Every live key has a daily spend limit set by HalalAdz (0 at first — the key cannot launch any campaign until a limit is set). If the budgets launched with this key today plus the new one go over the limit, you get
403 spend_limit_reachedbefore any money moves. Days are counted in Bangladesh time. You see the limit in Settings → API keys; write to HalalAdz to change it. - Only the account owner can make a live key, and the key acts with the owner's current role.
{
"error": "spend_limit_reached",
"message": "this launch would go over the key's daily spend limit",
"details": { "limitMicros": "5000000000", "usedMicros": "3000000000", "remainingMicros": "2000000000", "totalMicros": "3000000000", "day": "2026-12-05" }
}Campaigns with a test key
Run the whole flow first with a test key (hz_test_…). The campaign is a test campaign: the same checks, the same halal rules and the same review by a HalalAdz person — but the budget is test money, never from your wallet. It shows only on your own places that have "Test ads" on, never to real publishers, and nothing is earned or charged. When it ends or is rejected, the test money goes back to the test wallet. A test key sees only test campaigns, a live key only real ones (the other kind answers 404). Sandbox.
Reading campaigns
GET /campaigns
curl "https://api.halaladz.com/api/v1/campaigns?status=active&limit=20" \
-H "Authorization: Bearer $HALALADZ_KEY"const res = await fetch("https://api.halaladz.com/api/v1/campaigns?status=active&limit=20", {
headers: { Authorization: `Bearer ${process.env.HALALADZ_KEY}` },
});
const { items, nextCursor } = await res.json();<?php
$ch = curl_init('https://api.halaladz.com/api/v1/campaigns?status=active&limit=20');
curl_setopt_array($ch, [CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('HALALADZ_KEY')], CURLOPT_RETURNTRANSFER => true]);
$page = json_decode(curl_exec($ch), true);
// $page['items'], $page['nextCursor']import os
import requests
r = requests.get(
"https://api.halaladz.com/api/v1/campaigns",
params={"status": "active", "limit": 20},
headers={"Authorization": f"Bearer {os.environ['HALALADZ_KEY']}"},
timeout=30,
)
page = r.json() # page["items"], page["nextCursor"]Numbers per day: Reports API. Every request in full: API reference.