Skip to content

Segments

The Segments API allows you create and manage segments on your integration.

Create a Segment

Post
bash
https://api.bunce.so/v1/segment

Creates a new segment.

If successful, your response includes a copy of the new segment entity.

Request

Body Parameters required

name string requiredName of the Segment
description string<email> nullableDescription of the segment
add_all_customers boolean nullableSpecifies if all customers should be added to the segment

Example:

json
{
    "name": "My Test Segment",
    "description": "Test Segment created from API",
    "add_all_customers" : true
}
bash
curl --request POST \
  --url https://api.bunce.so/v1/segments \
  --header 'Content-Type: application/json' \
  --header 'X-Authorization: sk_live_************************' \
  --data '{
      "name": "My Test Segment",
      "description": "Test Segment created from API",
      "add_all_customers" : true
  }'
go
import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

url := "https://api.bunce.so/v1/segments"

payload := strings.NewReader("{\n  \"name\": \"My Test Segment\", \n  \"description\": \"Test Segment created from API\",\n  \"add_all_customers\": \"true\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("X-Authorization", "sk_live_************************")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))
js
import  from 'node-fetch'

let  = 'https://api.bunce.so/v1/segments'

let  = {
  : 'POST',
  : {
    'X-Authorization': 'sk_live_************************',
    'Content-Type': 'application/json',
  },
  : '{"name" : "My Test Segment","description":"Test Segment created from API","add_all_customers":"true"}',
}

(, )
  .then(() => .json())
  .then(() => .())
  .catch(() => .('error:' + ))
php
<?php

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append('{
    "name": "My Test Segment",
    "description": "Test Segment created from API",
    "add_all_customers" : true
}');

$request->setRequestUrl('https://api.bunce.so/v1/segments');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders([
  'X-Authorization' => 'sk_live_************************',
  'Content-Type' => 'application/json'
]);

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.bunce.so/v1/customers"))
    .header("X-Authorization", "sk_live_************************")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\n  \"name\": \"My Test Segment\", \n  \"description\": \"Test Segment created from API\",\n  \"add_all_customers\": \"true\"\n}"))
    .build();

HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());

System.out.println(response.body());

Response

json
{
  "success": true,
    "data": {
        "id": "9da67caa-b803-4691-a2b6-bdcd58008aaf",
        "name": "My Test Segment",
        "description": "API Test Segment",
        "conditions": null,
        "type": "automatic",
        "all_customers": 1,
        "created_at": "2024-12-05 08:30:16"
    },
    "message": "Segment created successfully"
}