Skip to content

Add customers to a Segment

Post
bash
https://api.bunce.so/v1/segments/{segment_id}/customers

Adds customers to a segment.

Request

Body Parameters required

customers array
  • customer_id string required if email is not present
  • email email required if customer_id is not present
  • first_name string optional
  • last_name string optional
  • phone_no string optional

A new customer record will be created for the customer object passed or updated if the customer email or customer_id already exist.

Example:

json
{
  "customers": [
    {
        "first_name": "Abdul",
        "last_name": "Bassey Tawo",
        "phone_no": "+2348106489348",
        "email": "abdul@gmail.com"
    },
    {
        "first_name": "Timothy",
        "last_name": "Micheal",
        "phone_no": "09088447387",
        "customer_id": "8998223462384236"
    }
  ]
}
bash
curl --request POST \
  --url https://api.bunce.so/v1/segments/{segment_id}/customers \
  --header 'Content-Type: application/json' \
  --header 'X-Authorization: sk_live_************************' \
  --data '{
  "customers": [
    {
        "first_name": "Abdul",
        "last_name": "Bassey Tawo",
        "phone_no": "+2348106489348",
        "email": "abdul@gmail.com"
    },
    {
        "first_name": "TImothy",
        "last_name": "Micheal",
        "phone_no": "09088447387",
        "email": "timothy@gmail.com"
    }
  ]
}'
go
import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

url := "https://api.bunce.so/v1/segments/{segment_id}/customers"

payload := strings.NewReader("{\n  \"customers\": [\n    {\n        \"first_name\": \"Abdul\",\n        \"last_name\": \"Bassey Tawo\",\n        \"phone_no\": \"+2348106489348\",\n        \"email\": \"abdul@gmail.com\"\n    },\n    {\n        \"first_name\": \"Timothy\",\n        \"last_name\": \"Micheal\",\n        \"phone_no\": \"09088447387\",\n        \"email\": \"timothy@gmail.com\"\n    }\n  ]\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/{segment_id}/customers'

let  = {
  : 'POST',
  : {
    'X-Authorization': 'sk_live_************************',
    'Content-Type': 'application/json',
  },
  : '{ "customers": [ { "first_name": "Abdul", "last_name": "Bassey Tawo", "phone_no": "+2348106489348", "email": "abdul@gmail.com" }, { "first_name": "Timothy", "last_name": "Micheal", "phone_no": "09088447387", "email": "timothy@gmail.com" } ] }',
}

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

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

$body = new http\Message\Body;
$body->append('{
  "customers": [
    {
        "first_name": "Abdul",
        "last_name": "Bassey Tawo",
        "phone_no": "+2348106489348",
        "email": "abdul@gmail.com"
    },
    {
        "first_name": "TImothy",
        "last_name": "Micheal",
        "phone_no": "09088447387",
        "email": "timothy@gmail.com"
    }
  ]
}');

$request->setRequestUrl('https://api.bunce.so/v1/segments/{segment_id}/customers');
$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/segment/{segment_id}/customers"))
    .header("X-Authorization", "sk_live_************************")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\n  \"customers\": [\n    {\n        \"first_name\": \"Abdul\",\n        \"last_name\": \"Bassey Tawo\",\n        \"phone_no\": \"+2348106489348\",\n        \"email\": \"abdul@gmail.com\"\n    },\n    {\n        \"first_name\": \"Timothy\",\n        \"last_name\": \"Micheal\",\n        \"phone_no\": \"09088447387\",\n        \"email\": \"timothy@gmail.com\"\n    }\n  ]\n}"))
    .build();


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

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

Response

json
{
  "success": true,
  "data": null,
  "message": "Customers added to segment successfully"
}