Batches: static and dynamic
A list somebody made, or a saved question. They make different promises.
Updated
On this page
There are exactly two honest ways to hold a set of contacts. They make different promises, and the design keeps them apart on purpose.
A static batch is a list somebody made. Rows say who is in it, and nothing but a person changes them. "The forty people from the trade show" means the same forty next Tuesday.
A dynamic batch is a saved question. "Customers tagged vip who have never been called" is answered against the contact table at the moment somebody asks, so its membership moves as the contacts do.
Why a dynamic batch stores no rows
The tempting shortcut is to materialise dynamic membership as rows too. One table, one code path, one count to read. It's the wrong trade.
Those rows are a photograph of a rule, and they are wrong the instant a contact is tagged, imported, archived or opted out. The failure isn't that the number drifts. It's that a campaign fires against last week's answer while the console shows a rule that no longer produces it, and nobody can see the gap.
So a dynamic batch materialises nothing, and pays for that with a query at resolve time.
Creating one
cURL
curl -X POST https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/ \
-H "Authorization: Bearer vox_sk_live_..." \
-H "Content-Type: application/json" \
-d '{"name": "Trade show, March", "kind": "static"}'Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
batch = httpx.post(
f"{BASE}/api/v1/orgs/{ORG}/contact-batches/",
headers=AUTH,
json={"name": "Trade show, March", "kind": "static"},
).json()Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
batch = vox.contact_batches.create(name="Trade show, March", kind="static")kind is static or dynamic, and it is
immutable after creation. A dynamic batch must carry a valid
rule; a static one must not. Names are unique per organization
among live batches.
The vocabulary a rule can use is served, not documented, so it can't go stale:
cURL
curl https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/fields/ \
-H "Authorization: Bearer vox_sk_live_..."Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
vocabulary = httpx.get(
f"{BASE}/api/v1/orgs/{ORG}/contact-batches/fields/", headers=AUTH
).json()
print(vocabulary["fields"], vocabulary["max_conditions"])Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
vocabulary = vox.request(
"GET", f"/api/v1/orgs/{vox.org}/contact-batches/fields/"
)
print(vocabulary["fields"], vocabulary["max_conditions"])You get back the available fields, the operators
each accepts, the matches modes, max_conditions and
scan_limit.
Membership
cURL
# Read the membership rows.
curl https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/<id>/members/ \
-H "Authorization: Bearer vox_sk_live_..."
# Pin people in, or hold them out with "state": "excluded".
curl -X POST https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/<id>/members/ \
-H "Authorization: Bearer vox_sk_live_..." \
-H "Content-Type: application/json" \
-d '{"contacts": ["con__..."], "state": "pinned", "reason": ""}'
# Drop the rows again.
curl -X DELETE https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/<id>/members/ \
-H "Authorization: Bearer vox_sk_live_..." \
-H "Content-Type: application/json" \
-d '{"contacts": ["con__..."]}'Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
members = f"{BASE}/api/v1/orgs/{ORG}/contact-batches/{batch_id}/members/"
rows = httpx.get(members, headers=AUTH).json()["data"]
httpx.post(
members, headers=AUTH, json={"contacts": ids, "state": "pinned"}
).raise_for_status()
httpx.post(
members,
headers=AUTH,
json={"contacts": [rival], "state": "excluded", "reason": "competitor"},
).raise_for_status()
httpx.request("DELETE", members, headers=AUTH, json={"contacts": ids})Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
for row in vox.contact_batches.members(batch_id):
print(row["state"], row["contact"])
vox.contact_batches.add(batch_id, ids)
# An exclusion is a POST with a different state, not a delete.
vox.request(
"POST",
f"/api/v1/orgs/{vox.org}/contact-batches/{batch_id}/members/",
json={"contacts": [rival], "state": "excluded", "reason": "competitor"},
)POST takes {"contacts": [ids], "state": "pinned"|"excluded",
"reason": "..."}, up to 500 ids at a time, and state
defaults to pinned. Pinning is refused on a dynamic batch. DELETE
takes {"contacts": [ids]} and removes the rows, which on a dynamic
batch means lifting an exclusion and putting somebody back if the rule still
matches them.
Exclusion is not the same as removal
An excluded membership answers a question a tag cannot. Somebody matches the rule and must not be contacted from this batch. They're a competitor, they complained, a colleague is already handling them. The alternatives are all worse. Editing their tags changes them everywhere, and setting do-not-call to keep one person out of one campaign is a legal flag being used as a filing device.
Exclusions are kept for static batches too, where "just remove the row" looks like it would do the job. It doesn't. Re-importing the same trade-show list puts them straight back, and an exclusion is the only form of "no" that survives the next import.
Counts
A static batch is counted live, in the same query that fetches the page. A dynamic batch can't be. Every row carries a different rule, and a rule with a tag in it is not a SQL count at all. So its figure is stored, stamped with when it was taken, and marked whether it was exact.
The payload carries member_count,
member_count_is_live, member_count_at and
member_count_is_exact. An approximate number that says when it was
taken beats an exact one that is quietly wrong.
cURL
curl -X POST https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/<id>/recount/ \
-H "Authorization: Bearer vox_sk_live_..."Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
counted = httpx.post(
f"{BASE}/api/v1/orgs/{ORG}/contact-batches/{batch_id}/recount/",
headers=AUTH,
).json()Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
counted = vox.request(
"POST", f"/api/v1/orgs/{vox.org}/contact-batches/{batch_id}/recount/"
)Previewing
cURL
curl https://api.voxcore.net/api/v1/orgs/<org_id>/contact-batches/<id>/preview/ \
-H "Authorization: Bearer vox_sk_live_..."Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
preview = httpx.get(
f"{BASE}/api/v1/orgs/{ORG}/contact-batches/{batch_id}/preview/",
headers=AUTH,
).json()
print(preview["count"], preview["channels"]["call"]["suppressed"])Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
preview = vox.request(
"GET", f"/api/v1/orgs/{vox.org}/contact-batches/{batch_id}/preview/"
)
print(preview["count"], preview["channels"]["call"]["suppressed"])You get paginated contacts, plus count,
count_is_exact, truncated, kind, and a
channels breakdown giving sendable,
suppressed and unreachable per channel.
Those last two are deliberately separate. A person with no phone number is not opted out. They're unreachable on that channel. Merging the two would make an empty batch impossible to explain.
Looking at a batch is not the same as sending to it
A preview includes suppressed contacts, on purpose. "This batch has 1,204 people, 37 of whom have opted out" is a sentence the preview screen needs to be able to write, and it can't if the opt-outs were filtered away upstream.
Anything that dials or texts goes through a different, narrower resolution that applies the suppression as a database clause. You can look at your opt-outs. You cannot send to them.
A dynamic rule may even ask for do_not_call is true. That's a
useful audit list, and the resulting batch comes back empty when it gets resolved
for sending.
The scan limit
Evaluating a rule with a tag in it decrypts rows, and that scan is bounded.
When it hits the bound, the response says so: truncated on a
preview, count_is_exact: false on a count. A caller that ignores
that flag is a caller that will one day send to five thousand of a tenant's
fifty thousand matches and report success.