curl --request POST \
--url https://brew.new/api/v1/audiences/from-events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"cohort": {
"eventTypes": [
"opened"
],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
}
}
'import requests
url = "https://brew.new/api/v1/audiences/from-events"
payload = { "cohort": {
"eventTypes": ["opened"],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
cohort: {
eventTypes: ['opened'],
from: '2026-07-04T00:00:00.000Z',
to: '2026-08-03T00:00:00.000Z'
}
})
};
fetch('https://brew.new/api/v1/audiences/from-events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://brew.new/api/v1/audiences/from-events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cohort' => [
'eventTypes' => [
'opened'
],
'from' => '2026-07-04T00:00:00.000Z',
'to' => '2026-08-03T00:00:00.000Z'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://brew.new/api/v1/audiences/from-events"
payload := strings.NewReader("{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://brew.new/api/v1/audiences/from-events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://brew.new/api/v1/audiences/from-events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}"
response = http.request(request)
puts response.read_body{
"audienceId": "jn7a8w4q8m9k2p1x7c3b5v6n9h7s2d4f",
"audienceName": "Openers · Jul 4 – Aug 3, 2026",
"filters": {
"filters": [
{
"field": "customFields.openedJul4Aug3",
"operator": "is_not_empty",
"type": "date"
}
],
"logicalOperator": "and"
},
"count": 0,
"createdAt": "2026-04-08T12:34:56.789Z",
"updatedAt": "2026-04-08T12:34:56.789Z",
"materializationStatus": "pending",
"build": {
"jobId": "kh7c2m4q8n9w2p1x7c3b5v6n9h7s2d4f",
"status": "pending",
"cohort": {
"eventTypes": [
"opened"
],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
},
"field": {
"key": "openedJul4Aug3",
"label": "Opened Jul 4 – Aug 3",
"type": "date"
},
"counts": {
"eventsScanned": 0
},
"enqueuedAt": "2026-08-03T12:00:00.000Z"
}
}{
"error": {
"code": "INVALID_REQUEST",
"type": "invalid_request",
"message": "Request validation failed.",
"suggestion": "Fix the field reported in `param` and retry.",
"docs": "https://docs.brew.new/api-reference/api/errors",
"param": "cohort"
}
}{
"error": {
"code": "INVALID_API_KEY",
"type": "authentication_error",
"message": "The provided API key is invalid.",
"suggestion": "Check the API key format and retry with a valid active key.",
"docs": "https://docs.brew.new/api-reference/api/authentication"
}
}{
"error": {
"code": "INSUFFICIENT_PERMISSIONS",
"type": "authorization_error",
"message": "The caller does not have the required permission.",
"suggestion": "Use an API key or session with the required permission.",
"docs": "https://docs.brew.new/api-reference/api/authentication",
"param": "contacts"
}
}{
"error": {
"code": "IDEMPOTENCY_CONFLICT",
"type": "conflict",
"message": "The same idempotency key was reused with a different request payload.",
"suggestion": "Reuse the original payload or send a new idempotency key.",
"docs": "https://docs.brew.new/api-reference/api/idempotency"
}
}{
"error": {
"code": "RATE_LIMITED",
"type": "rate_limit",
"message": "Too many requests.",
"suggestion": "Wait for the retry window before sending another request.",
"docs": "https://docs.brew.new/api-reference/api/rate-limits",
"retryAfter": 42
}
}{
"error": {
"code": "INTERNAL_ERROR",
"type": "internal_error",
"message": "An unexpected error occurred.",
"suggestion": "Retry the request. If it keeps failing, contact support.",
"docs": "https://docs.brew.new/api-reference/api/errors"
}
}Create an audience from analytics events
Creates a frozen audience snapshot from the same membership filters as /events: 1–10 canonical event types, an absolute window up to 90 days, optional send/email ids, multi-select automation/audience ids, recipient include/exclude rules, and the machine-click policy. Every call generates a unique date field; each matching existing contact stores its latest matching-event timestamp. Returns 201 immediately with materializationStatus: pending plus build progress. The audience is unavailable for campaign, smart-send, and automation delivery until the status becomes ready. Failed/partial/stale builds remain non-sendable and partial values are cleaned. Poll GET /v1/audiences?audienceId=…&include=build.
curl --request POST \
--url https://brew.new/api/v1/audiences/from-events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"cohort": {
"eventTypes": [
"opened"
],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
}
}
'import requests
url = "https://brew.new/api/v1/audiences/from-events"
payload = { "cohort": {
"eventTypes": ["opened"],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
cohort: {
eventTypes: ['opened'],
from: '2026-07-04T00:00:00.000Z',
to: '2026-08-03T00:00:00.000Z'
}
})
};
fetch('https://brew.new/api/v1/audiences/from-events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://brew.new/api/v1/audiences/from-events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cohort' => [
'eventTypes' => [
'opened'
],
'from' => '2026-07-04T00:00:00.000Z',
'to' => '2026-08-03T00:00:00.000Z'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://brew.new/api/v1/audiences/from-events"
payload := strings.NewReader("{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://brew.new/api/v1/audiences/from-events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://brew.new/api/v1/audiences/from-events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cohort\": {\n \"eventTypes\": [\n \"opened\"\n ],\n \"from\": \"2026-07-04T00:00:00.000Z\",\n \"to\": \"2026-08-03T00:00:00.000Z\"\n }\n}"
response = http.request(request)
puts response.read_body{
"audienceId": "jn7a8w4q8m9k2p1x7c3b5v6n9h7s2d4f",
"audienceName": "Openers · Jul 4 – Aug 3, 2026",
"filters": {
"filters": [
{
"field": "customFields.openedJul4Aug3",
"operator": "is_not_empty",
"type": "date"
}
],
"logicalOperator": "and"
},
"count": 0,
"createdAt": "2026-04-08T12:34:56.789Z",
"updatedAt": "2026-04-08T12:34:56.789Z",
"materializationStatus": "pending",
"build": {
"jobId": "kh7c2m4q8n9w2p1x7c3b5v6n9h7s2d4f",
"status": "pending",
"cohort": {
"eventTypes": [
"opened"
],
"from": "2026-07-04T00:00:00.000Z",
"to": "2026-08-03T00:00:00.000Z"
},
"field": {
"key": "openedJul4Aug3",
"label": "Opened Jul 4 – Aug 3",
"type": "date"
},
"counts": {
"eventsScanned": 0
},
"enqueuedAt": "2026-08-03T12:00:00.000Z"
}
}{
"error": {
"code": "INVALID_REQUEST",
"type": "invalid_request",
"message": "Request validation failed.",
"suggestion": "Fix the field reported in `param` and retry.",
"docs": "https://docs.brew.new/api-reference/api/errors",
"param": "cohort"
}
}{
"error": {
"code": "INVALID_API_KEY",
"type": "authentication_error",
"message": "The provided API key is invalid.",
"suggestion": "Check the API key format and retry with a valid active key.",
"docs": "https://docs.brew.new/api-reference/api/authentication"
}
}{
"error": {
"code": "INSUFFICIENT_PERMISSIONS",
"type": "authorization_error",
"message": "The caller does not have the required permission.",
"suggestion": "Use an API key or session with the required permission.",
"docs": "https://docs.brew.new/api-reference/api/authentication",
"param": "contacts"
}
}{
"error": {
"code": "IDEMPOTENCY_CONFLICT",
"type": "conflict",
"message": "The same idempotency key was reused with a different request payload.",
"suggestion": "Reuse the original payload or send a new idempotency key.",
"docs": "https://docs.brew.new/api-reference/api/idempotency"
}
}{
"error": {
"code": "RATE_LIMITED",
"type": "rate_limit",
"message": "Too many requests.",
"suggestion": "Wait for the retry window before sending another request.",
"docs": "https://docs.brew.new/api-reference/api/rate-limits",
"retryAfter": 42
}
}{
"error": {
"code": "INTERNAL_ERROR",
"type": "internal_error",
"message": "An unexpected error occurred.",
"suggestion": "Retry the request. If it keeps failing, contact support.",
"docs": "https://docs.brew.new/api-reference/api/errors"
}
}Authorizations
Send your Brew API key as Authorization: Bearer brew_xxx.
Headers
Optional idempotency key for safe retries. Reusing the same key with the same request body returns the original response for 24 hours.
1 - 100The brand this request acts on. REQUIRED for organization-scoped credentials (otherwise 400 BRAND_ID_REQUIRED — there is no default brand); list ids with GET /v1/brands. Brand-scoped credentials may omit it, and sending a different brand returns 403 BRAND_SCOPE_MISMATCH. A brand outside your organization returns 404 BRAND_NOT_FOUND.
1 - 64Body
Response
Created. The audience exists immediately; build tracks the background stamping run.
1 - 641 - 200Show child attributes
Show child attributes
x >= 0pending, running, ready, failed Show child attributes
Show child attributes
Was this page helpful?