Newer Version Available
Example: Add Event Enrichment Fields with Tooling API
If the channel member you are enriching is part of a custom channel, create the custom channel first, as shown in this example. You can skip this step if using the ChangeEvents standard channel, or if you created the custom channel earlier.
Make a POST request to this REST endpoint:
1/services/data/v48.0/tooling/sobjects/PlatformEventChannelRequest body for the custom channel:
1{
2 "FullName": "SalesEvents__chn",
3 "Metadata": {
4 "channelType": "data",
5 "label": "Custom Channel for Sales App"
6 }
7}To add enrichment fields, perform a REST request that creates a PlatformEventChannelMember component using Tooling API. In this example, the component contains two enriched fields in the enrichedFields array for AccountChangeEvent on the SalesEvents custom channel. External_Account_ID__c is a custom field defined in your org.
Make a POST request to this REST endpoint (API version 48.0 and later):
1/services/data/v48.0/tooling/sobjects/PlatformEventChannelMemberRequest body with enrichment fields added in a channel member:
1{
2 "FullName": "SalesEvents_AccountChangeEvent",
3 "Metadata": {
4 "enrichedFields": [
5 {
6 "name": "External_Account_ID__c"
7 },
8 {
9 "name": "Industry"
10 }
11 ],
12 "eventChannel": "SalesEvents__chn",
13 "selectedEntity": "AccountChangeEvent"
14 }
15}To find out which channel members and fields you configured, query the EnrichedField object in Tooling API. For example, this query returns the selected enriched field and the channel member ID.
1Select Field,ChannelMemberId FROM EnrichedFieldIn these query results, the first field is the enriched field and the second is the ID of the channel member. The custom field is returned as an ID.
1Industry,0v8RM00000000JsYAI
200NRM000001gEx32AE,0v8RM00000000JsYAI