Skip to main content
POST
/
accounts
/
{account_id}
/
audiences
JavaScript
import Surge from '@surgeapi/node';

const client = new Surge({
  apiKey: process.env['SURGE_API_KEY'], // This is the default and can be omitted
});

const audience = await client.audiences.create('acct_01j9a43avnfqzbjfch6pygv1td', {
  name: 'The Family',
});

console.log(audience.id);
import os
from surge import Surge

client = Surge(
api_key=os.environ.get("SURGE_API_KEY"), # This is the default and can be omitted
)
audience = client.audiences.create(
account_id="acct_01j9a43avnfqzbjfch6pygv1td",
name="The Family",
)
print(audience.id)
package main

import (
"context"
"fmt"

"github.com/stainless-sdks/surge-go"
"github.com/stainless-sdks/surge-go/option"
)

func main() {
client := surge.NewClient(
option.WithAPIKey("My API Key"),
)
audience, err := client.Audiences.New(
context.TODO(),
"acct_01j9a43avnfqzbjfch6pygv1td",
surge.AudienceNewParams{
Name: "The Family",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", audience.ID)
}
require "surge_api"

surge = SurgeAPI::Client.new(api_key: "My API Key")

audience = surge.audiences.create("acct_01j9a43avnfqzbjfch6pygv1td", name: "The Family")

puts(audience)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Surge\Client;
use Surge\Core\Exceptions\APIException;

$client = new Client(apiKey: getenv('SURGE_API_KEY') ?: 'My API Key');

try {
$audience = $client->audiences->create(
'acct_01j9a43avnfqzbjfch6pygv1td', name: 'The Family'
);

var_dump($audience);
} catch (APIException $e) {
echo $e->getMessage();
}
curl --request POST \
--url https://api.surge.app/accounts/{account_id}/audiences \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "The Family"
}
'
HttpResponse<String> response = Unirest.post("https://api.surge.app/accounts/{account_id}/audiences")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"The Family\"\n}")
.asString();
{
  "id": "aud_01j9dy8mdzfn3r0e8x1tbdrdrf",
  "name": "The Family"
}
{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

account_id
string
required

The account for which the audience should be created.

Example:

"acct_01j9a43avnfqzbjfch6pygv1td"

Body

application/json

Params for creating an audience

name
string
required

The audience name.

Maximum string length: 255

Response

Created audience

A group of contacts used for targeting messages.

id
string
required

Unique identifier for the object.

name
string
required

A name to identify this Audience. This name will only be visible within Surge.

Maximum string length: 255