Example: Add Event Enrichment Fields with Tooling API
To add event enrichment fields, use the PlatformEventChannelMember Tooling API object, and specify the fields, the channel, and channel member.
To carry out similar steps in Trailhead and earn a badge, check out Create a Custom Channel and Enrich Change Events.
If the channel member you’re 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:
Request body for the custom channel:
To add enrichment fields, perform a REST request that creates a PlatformEventChannelMember component by using Tooling API. In this example, the component contains three enriched fields in the enrichedFields array for AccountChangeEvent on the SalesEvents custom channel. Before you create this channel member, create a custom Text(20) field for Account with the label External Account ID.
Make a POST request to this REST endpoint (API version 51.0 or later is supported for enrichment fields):
Request body with enrichment fields added in a channel member:
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.
You can perform a query using the Query Editor in the Developer Console and by checking Use Tooling API. For more information, see Developer Console Query Editor in Salesforce Help.
Alternatively, you can run a query using REST API. Perform a GET request to the following URI. The URI includes the query with spaces replaced with +.
In these query results, the rows returned are for the same channel member. They contain these enriched fields: Industry, the External_Account_ID__c custom field, whose value is an ID, and BillingAddress.
| ChannelMemberId | Field |
|---|---|
| 0v8RM00000000JsYAI | Industry |
| 0v8RM00000000JsYAI | 00NRM000001gEx32AE |
| 0v8RM00000000JsYAI | BillingAddress |
If there’s an existing channel member for the same selected entity and channel, you can’t create a duplicate channel member with a POST request. Instead, update the channel member with a PATCH request. Alternatively, you can delete the channel member and recreate it with the enriched fields.
To update a channel member, follow these steps.
-
If you’re using a custom channel, get the channel ID by running this query:
DeveloperNamedoesn’t contain the__chnsuffix of a custom channel name. For example, for the SalesEvents__chn channel, the query would be: -
Get the channel member ID with this Tooling API query. For a custom channel, replace Channel_ID with the ID you got in the previous step, or for the standard ChangeEvents channel, replace Channel_ID with
ChangeEvents. ReplaceEntityChangeEventwith the selected entity name.For example, for AccountChangeEvent on custom channel ID
0YLRM00000000434AA, the query looks as follows.Or for the standard ChangeEvents channel, the full URI would be:
-
Make a PATCH request to this URI and append the channel member ID you got in the previous step.
In the request body, include the JSON definition of the channel member. For example, to update AccountChangeEvent on the channel member ID of
0v8RM00000000JsYAIand set the enriched fields to be thePhonefield only, make a PATCH request to this URI:With this request body:
If the channel member was previously configured with enriched fields, the update clears them and replaces them with the fields specified in the request body. This example specifies only one enriched field, the
Phonefield. If the channel member didn’t contain enriched fields, the update adds the specified enriched fields.For PATCH requests, include the full definition of a PlatformEventChannelMember. Partial definitions with only the enriched fields aren’t supported.
See Also