Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!

Is it possible to update multiple segments in bulk using segment API

Avatar

Community Advisor

Hi is there a way to update segments in bulk using segment API, apparently the update segment API has a required id parameter but it only support single id at a time.

Ankit_Chaudhary_0-1718166313632.png

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 2

Hello,

 

Currently, the Segment API requires the segment ID parameter for updates and only supports updating one segment at a time. Unfortunately, there is no direct way to update multiple segments in bulk using a single API call.

However, you can automate the process of updating segments in bulk by scripting the API calls. Here’s a general approach you can follow:

  1. Retrieve Segment IDs: Use the API to fetch the list of segment IDs you want to update.
  2. Loop Through IDs: Write a script (in Python, for example) to loop through each segment ID and make individual API calls to update the segments.

Here’s a simple example in Python:

 

import requests # Define your API endpoint and headers api_endpoint = 'https://api.segment.yourservice.com/v1/segments/' headers = { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Content-Type': 'application/json' } # List of segment IDs to update segment_ids = ['segment_id_1', 'segment_id_2', 'segment_id_3'] # Data to update for each segment update_data = { 'key1': 'value1', 'key2': 'value2' } # Function to update a single segment def update_segment(segment_id, data response = requests.put(api_endpoint + segment_id, headers=headers, json=data) return response.json() # Loop through segment IDs and update them for segment_id in segment_ids: result = update_segment(segment_id, update_data) print(f'Segment {segment_id} update result: {result}')
 

This script fetches segment IDs and updates each segment individually by looping through the list of IDs and making PUT requests to the API. While it's not a single bulk operation, this method achieves the same result efficiently Sobha Crystal Meadows Price

Avatar

Community Advisor

Hey @Nikhilk2 

Thanks for the response.

Well I was trying the adobe analytics python wrapper by any chance have you used this?

I've used it before for Data insertion API but not with segment API, let me know if you have any best practices for this.