# Creating a Parent Segment That Supports Group Hierarchy Group hierarchy improves a marketer's insights into customers and enables the delivery more consistent messaging to specific audiences. The steps required to create a parent (master) segment that supports group hierarchy are: 1. Make an API Call to the *[/audiences](https://api-docs.treasuredata.com/pages/audience_api_v1/overview/)* endpoint to create the parent segment. 2. Use TD Console to run the parent segment. ## Making the API Call to Create the Parent Segment that Supports Group Hierarchy You can create a parent segment that supports group hierarchy as follows: * Use a POST API call to create a new parent segment * Use a PATCH API call to insert a customerGroup into an existing parent segment ## Using the POST API to Create a New Parent Segment with Group Hierarchy To make the POST API call to the `_/audiences_` endpoint, you will need to specify a JSON object (or request payload) that defines the parent segment you want to create. Figure 1 is the listing of the file wt_hg_parentSegmentPost.json. This file contains a request object that will create a parent segment. In this example, the database used is acme_db , the new parent segment will be named wt_hg_parentSegment , and the customer group (or group hierarchy) created is named account. Here is an example of a cURL command that calls the API with the JSON file: ```bash curl -X POST 'https://api-cdp.treasuredata.com/audiences/' \ -H 'AUTHORIZATION: TD1 1/123456789abcdef0123456789abcdef012345678' \ -H 'Content-Type: application/json' -d @wt_hg_parentSegmentPost.json ``` If successful, the API call returns a JSON object that describes the new parent segment. Here is a partially collapsed example of what is returned: ![hg_ps](/assets/hg_ps.7237f580071eb5c50683df992833c490662deae84f87115dd43ce7a3dfbc400c.cf3845cb.png) details summary Figure 1 ```json { "name":"wt_hg_parentSegment", "description":"working segment", "scheduleType":"none", "scheduleOption":null, "timezone":"America/Denver", "master":{ "parentDatabaseName":"acme_db", "parentTableName":"contacts" }, "attributes":[ { "name":"lead_id", "parentDatabaseName":"acme_db", "parentTableName":"leads", "parentColumn":"lead_id", "parentKey":"email", "foreignKey":"email", "matrixColumnName":"lead_id" }, { "name":"name", "parentDatabaseName":"acme_db", "parentTableName":"leads", "parentColumn":"name", "parentKey":"email", "foreignKey":"email", "matrixColumnName":"name" }, { "name":"lead_created_time", "parentDatabaseName":"acme_db", "parentTableName":"leads", "parentColumn":"lead_created_time", "parentKey":"email", "foreignKey":"email", "matrixColumnName":"lead_created_time" }, { "name":"lead_created_time_sisense", "parentDatabaseName":"acme_db", "parentTableName":"leads", "parentColumn":"lead_created_time_sisense", "parentKey":"email", "foreignKey":"email", "matrixColumnName":"lead_created_time_sisense" }, { "name":"auto_increment_id", "parentDatabaseName":"acme_db", "parentTableName":"leads", "parentColumn":"auto_increment_id", "parentKey":"email", "foreignKey":"email", "matrixColumnName":"auto_increment_id" }, { "name":"count_visit_webpage", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_visit_webpage", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_visit_webpage" }, { "name":"count_click_links", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_click_links", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_click_links" }, { "name":"count_search", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_search", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_search" }, { "name":"count_input_contact_form", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_input_contact_form", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_input_contact_form" }, { "name":"count_send_email", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_send_email", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_send_email" }, { "name":"count_signup_free_plan", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_signup_free_plan", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_signup_free_plan" }, { "name":"count_signup_business_plan", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_signup_business_plan", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_signup_business_plan" }, { "name":"count_signup_enterprise_plan", "parentDatabaseName":"acme_db", "parentTableName":"contact_derived_attributes", "parentColumn":"count_signup_enterprise_plan", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"count_signup_enterprise_plan" }, { "name":"average_score", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"average_score", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"average_score" }, { "name":"score_product_a", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"score_product_a", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"score_product_a" }, { "name":"score_product_b", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"score_product_b", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"score_product_b" }, { "name":"score_product_c", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"score_product_c", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"score_product_c" }, { "name":"score_product_d", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"score_product_d", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"score_product_d" }, { "name":"score_product_e", "parentDatabaseName":"acme_db", "parentTableName":"contact_predictive_scores", "parentColumn":"score_product_e", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixColumnName":"score_product_e" } ], "behaviors":[ { "name":"opportunities", "parentDatabaseName":"acme_db", "parentTableName":"opportunities", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixDatabaseName":"cdp_audience_47462", "matrixTableName":"behavior_opportunities", "allColumns":true, "scheduleType":"none", "scheduleOption":null }, { "name":"weblogs", "parentDatabaseName":"acme_db", "parentTableName":"weblogs", "parentKey":"email", "foreignKey":"email", "matrixDatabaseName":"cdp_audience_47462", "matrixTableName":"behavior_weblogs", "allColumns":true, "scheduleType":"none", "scheduleOption":null }, { "name":"contact_events", "parentDatabaseName":"acme_db", "parentTableName":"contact_events", "parentKey":"contact_id", "foreignKey":"contact_id", "matrixDatabaseName":"cdp_audience_47462", "matrixTableName":"behavior_contact_events", "allColumns":true, "scheduleType":"none", "scheduleOption":null } ], "customerGroup":{ "name":"account", "parentDatabaseName":"acme_db", "parentTableName":"accounts", "parentKey":"account_id", "foreignKey":"account_id", "customerGroupAttributes":[ { "name":"location", "parentDatabaseName":"acme_db", "parentTableName":"account_brands", "parentColumn":"location", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"industry", "parentDatabaseName":"acme_db", "parentTableName":"account_brands", "parentColumn":"industry", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"established_at", "parentDatabaseName":"acme_db", "parentTableName":"account_brands", "parentColumn":"established_at", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"established_at_sisense", "parentDatabaseName":"acme_db", "parentTableName":"account_brands", "parentColumn":"established_at_sisense", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"contract_started_at", "parentDatabaseName":"acme_db", "parentTableName":"account_contracts", "parentColumn":"contract_started_at", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"contract_last_confirmed_at", "parentDatabaseName":"acme_db", "parentTableName":"account_contracts", "parentColumn":"contract_last_confirmed_at", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"contract_started_at_sisense", "parentDatabaseName":"acme_db", "parentTableName":"account_contracts", "parentColumn":"contract_started_at_sisense", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"contract_last_confirmed_at_sisense", "parentDatabaseName":"acme_db", "parentTableName":"account_contracts", "parentColumn":"contract_last_confirmed_at_sisense", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"total_amount", "parentDatabaseName":"acme_db", "parentTableName":"account_contracts", "parentColumn":"total_amount", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"score_product_a", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"score_product_a", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"score_product_b", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"score_product_b", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"score_product_c", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"score_product_c", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"score_product_d", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"score_product_d", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"score_product_e", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"score_product_e", "parentKey":"account_id", "foreignKey":"account_id" }, { "name":"average_score", "parentDatabaseName":"acme_db", "parentTableName":"account_predictive_scores", "parentColumn":"average_score", "parentKey":"account_id", "foreignKey":"account_id" } ], "customerGroupBehaviors":[ { "name":"opportunities", "parentDatabaseName":"acme_db", "parentTableName":"opportunities", "parentKey":"account_id", "foreignKey":"account_id", "allColumns":false, "schema":[ { "name":"timestamp_sisense", "parentColumn":"timestamp_sisense" }, { "name":"stagename", "parentColumn":"stagename" }, { "name":"product2", "parentColumn":"product" }, { "name":"type", "parentColumn":"type" }, { "name":"amount", "parentColumn":"amount" } ] } ] } } ``` ## Using the PATCH API to Enable an Existing Parent Segment for Group Hierarchy To make the PATCH API call to the */audiences* endpoint, you will need to specify a request object (or request payload) that specifies the customerGroup that will be inserted into the parent segment. This request object is nearly identical to the wt_hg_parentSegmentPost.json request object used by the POST API call (shown in Figure 1), except lines 2-6 have been removed. ![hg_ps_patchIn](/assets/hg_ps_patchin.1c6598f0ddf752e980a7aa4a5b3642296a8a5bec01a0b12a9c2abef355877a6a.cf3845cb.png) After creating the request object,, save it as a file (e.g. wt_hg_parentSegmentPatch.json) and then PATCH the `/audiences/ ` endpoint. In the following example, an audienceId of 278153 is used. ```bash curl -X PATCH 'https://api-cdp.treasuredata.com/audiences/278153' -H 'AUTHORIZATION: TD1 1/123456789abcdef0123456789abcdef012345678' -H 'Content-Type: application/json' -d @wt_hg_parentSegmentPatch.json | jq . { "id": "278153", "name": "wtt_parentSegment1", "description": "working segment", "scheduleType": "none", "scheduleOption": null, "timezone": "America/Denver", "createdAt": "2022-07-19T15:56:10.324Z", "updatedAt": "2022-07-19T19:34:26.780Z", "createdBy": { "id": "10430", "td_user_id": "49717", "name": "wtt" }, "updatedBy": { "id": "10430", "td_user_id": "49717", "name": "wtt" }, "matrixUpdatedAt": null, "workflowHiveOnly": false, "hiveEngineVersion": "cdpaudience", "hivePoolName": null, "prestoPoolName": null, "population": null, "rootFolderId": "439171", "master": { "parentDatabaseName": "acme_db", "parentTableName": "contacts" }, "attributes": [ { "audienceId": "278153", "id": "1657919", . . . ``` ## Running the Parent Segment from the TD Console To run the newly created parent segment: 1. From TD Console, navigate to **Data Workbench > Master Segments**. 2. Locate the parent segment you created by searching for its name or entering the parent segment ID in the console URL. In this example, the parent segment's ID is 278153. 3. On the Master Segments pane, select **Run**. ![creating-a-parent-segment-that-supports-hg](/assets/creating-a-parent-segment-that-supports-hg-2024-05-31.c866bf6a5400b9910da01d62aa9ce4ce389ebcf169ef3973946a24018d516f6c.cf3845cb.png) TD Console runs the workflow and reports success on the Workflows pane. You can now create batch segments from the parent segment. If you want to see the new parent segment in Audience Studio, the feature flag will need to be enabled on the parent segment. Contact customer support for assistance with this request. ## Creating the Request Payload for the API When you call the API to create a parent segment that supports group hierarchy, you will need to define a request object containing the parent segment's attributes and behaviors. Additionally, this request payload will contain the customerGroup's name, customerGroupAttributes, and customerGroupBehaviors. Here is an abridged representation of the request object's structure. ![hgEnabledPSabridged](/assets/hgenabledpsabridged2.828be29baddbcdb5af160791d5e6c1da64ecf0d66b67e2505c017b3d87971e12.cf3845cb.png)