Is it possible to update multiple segments in bulk using segment API | Community
Skip to main content
Ankit_Chaudhary
Community Advisor
Community Advisor
June 12, 2024
Question

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

  • June 12, 2024
  • 1 reply
  • 1137 views

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.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 1
June 12, 2024

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

Ankit_Chaudhary
Community Advisor
Community Advisor
June 12, 2024

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.