Skip to content

Update a Segment

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

Update a segment using its ID

If successful, your response includes a copy of the updated attribute entity. If there is an error with any of the parameters, it will return a 422 HTTP status code with details in an error object.

Request

Route Parameters attribute_id (string<uuid>)

Body Parameters required

name string nullableSegment name
description string<text,nullable> nullableSegment Description
bash
curl --request PATCH \
  --url https://api.bunce.so/v1/segments/9da67caa-b803-4691-a2b6-bdcd58008aaf \
  --header 'Content-Type: application/json' \
  --header 'X-Authorization: sk_live_************************' \
  --data '{
      "name" : "New Segment Name",
      "description" : "Updated Segment Description"
}'
go
import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

url := "https://api.bunce.so/v1/segments/9da67caa-b803-4691-a2b6-bdcd58008aaf"

payload := strings.NewReader("{\n  \"name\": \"New Segment Name\",\n  \"description\": \"Updated Segment Description\",\n}")

req, _ := http.NewRequest("PATCH", 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/9da67caa-b803-4691-a2b6-bdcd58008aaf'

let  = {
  : 'PATCH',
  : {
    'X-Authorization': 'sk_live_************************',
    'Content-Type': 'application/json',
  },
  : '{"name" : "New Segment Name", "description" : "Updated Segment Description"}',
}

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

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

$body = new http\Message\Body;
$body->append('{
  "name": "New Segment Name",
  "description": "Updated Segment Description"
}');

$request->setRequestUrl('https://api.bunce.so/v1/segments/9da67caa-b803-4691-a2b6-bdcd58008aaf');
$request->setRequestMethod('PATCH');
$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/segments/9da67caa-b803-4691-a2b6-bdcd58008aaf"))
    .header("X-Authorization", "sk_live_************************")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("{\n  \"name\": \"New Segment name\",\n  \"description\": \"Updated Segment Description\",\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": "New Segment Name",
        "description": "Updated Segment Description",
        "conditions": null,
        "type": "manual",
        "all_customers": 1,
        "created_at": "2024-12-05 08:30:16"
    },
    "message": "Segment updated successfully"
}