SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How To use Public API to delete Audience

Objective

This article explains how to delete one or more Engage audiences programmatically using the Segment Public API, including:

  • the DELETE /spaces/{spaceId}/audiences/{audienceId} endpoint, 
  • the token access required, 
  • the 50 requests-per-minute rate limit to plan for during bulk clean-ups, and 
  • the follow-up needed for any Journeys that reference a deleted audience

It is aimed at workspaces running data-hygiene or housekeeping activities that need to remove a large number of legacy or inactive audiences.

 

Product

Twilio Segment

 

Environment

Segment Console

 

User Account Permission/Role(s) Required 

A Public API token with Unify and Engage Admin permission.

 

Procedure 

Follow these steps to programmatically delete your Engage audiences:

  1. Generate a Public API token. In the Segment app, go to Settings → Workspace Settings → Access Management → Tokens, create a token with Workspace Owner access, and store it securely. This is the token you'll pass as a Bearer credential.
  2. Identify the Space ID and Audience ID. The Space ID has the form spa_xxx and the Audience ID has the form aud_xxx. You can find the Audience ID in the audience's URL in the Segment app, or by listing audiences using GET https://api.segmentapis.com/spaces/{spaceId}/audiences. Use the Audience ID, not the audience name — the delete endpoint expects the aud_xxx ID.
  3. Delete the audience. Call the Remove Audience from Space endpoint:
   curl --request DELETE \
     --url https://api.segmentapis.com/spaces/{spaceId}/audiences/{audienceId} \
     --header 'Authorization: Bearer <YOUR_API_TOKEN>'
  1. Pace the calls for bulk runs. The delete endpoint is rate-limited to 50 requests per minute. When deleting a large batch, throttle your requests to stay under this limit and handle any 429 Too Many Requests responses with a short back-off and retry, rather than firing all deletions at once — otherwise the run will start erroring partway through.
  2. Review Journeys after deletion. Deleting an audience does not cascade into Journeys. Users already in flight continue through their steps unaffected and the deletion itself is not blocked, but any Journey that used the deleted audience as an entry condition will be left pointing at an audience that no longer exists. In Journeys v2 this surfaces as an "audience no longer exists" validation error. For any in-scope audiences used as a Journey entry condition, identify them beforehand and repoint or retire the Journey in the UI as part of the clean-up. This step is done manually in the Segment app.
  3. Destinations require no separate clean-up. Once the audience is deleted, any connected destinations simply stop receiving that audience's data. You do not need to remove or update the destination connections separately.

 

Additional Information 

  • Full set of Audience endpoints (including List Audiences): Audiences
  • Deleting an audience generates an Audience Deleted event in the workspace Audit Trail, which can be used to confirm a bulk run completed as expected.

 

Have more questions? Submit a request
Powered by Zendesk