Create audiences
// -------------------------------------------------------------------------- //
// Create audiences. //
// -------------------------------------------------------------------------- //
// ------------------------- Anonymous users audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_logged_in\",\"value\":false,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Anonymous Users",
"project_id": {{projectId}}
}
###
// ------------------------- Authenticated users audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_logged_in\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Authenticated Users",
"project_id": {{projectId}}
}
###
// ------------------------- Recent purchasers audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"days_since_last_order\",\"type\":\"custom_attribute\",\"match_type\":\"le\",\"value\":14}]]]",
"name": "Recent Purchasers",
"project_id": {{projectId}}
}
###
// ------------------------- California visitors audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"region_state\",\"type\":\"custom_attribute\",\"value\":\"CA\"}]]]",
"name": "California Visitors",
"project_id": {{projectId}}
}
###
// ------------------------- Mobile Web audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_mobile_user\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Mobile Web Users",
"project_id": {{projectId}}
}
###
// ------------------------- Mobile App users audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_mobile_app\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Mobile App Users",
"project_id": {{projectId}}
}
###
// ------------------------- QA Team 1 audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\", {\"value\": true,\"type\": \"custom_attribute\",\"name\": \"is_qa\"}]],[\"or\",[\"or\",{\"name\":\"qa_team\",\"type\":\"custom_attribute\",\"value\":\"1\"}]]]",
"name": "QA Team 1",
"project_id": {{projectId}}
}
###
// ------------------------- QA Team 2 audience ------------------------ //
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}
{
"conditions": "[\"and\",[\"or\",[\"or\", {\"value\": true,\"type\": \"custom_attribute\",\"name\": \"is_qa\"}]],[\"or\",[\"or\",{\"name\":\"qa_team\",\"type\":\"custom_attribute\",\"value\":\"2\"}]]]",
"name": "QA Team 2",
"project_id": {{projectId}}
}Create audiences to control who sees your flag rules using the Create an Audience API endpoint.
A single audience is defined based on custom user attributes you create.
Prerequisite
Before running this request, you must follow the instructions to configure your REST API cookbook.
Create a file
Create a file named create-audiences.rest and copy and paste the recipe into the file.
Configure API
{{baseUrl}} and {{token}} are defined in the settings.json file. Ensure you have configured your Visual Studio Code project correctly. See Configure the Visual Studio Code REST Client.
POST {{baseUrl}}/audiences
Content-Type: application/json
Authorization: {{token}}Create "Anonymous Users" audience
Create an audience named "Anonymous Users" where the is_logged_in attribute is false. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the previous step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_logged_in\",\"value\":false,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Anonymous Users",
"project_id": {{projectId}}
}The ### delimiter
The REST Client extension delimits multiple requests using ###. See Main features in the REST Client documentation.
Create "Authenticated Users" audience
Create an audience named "Authenticated Users" where the is_logged_in attribute is true. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_logged_in\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Authenticated Users",
"project_id": {{projectId}}
}Create "Recent Purchasers" audience
Create an audience named "Recent Purchasers" where the days_since_last_order attribute's value is 14. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"days_since_last_order\",\"type\":\"custom_attribute\",\"match_type\":\"le\",\"value\":14}]]]",
"name": "Recent Purchasers",
"project_id": {{projectId}}
}Create "California Visitors" audience
Create an audience named "California Visitors" where the region_state attribute's value is CA. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"region_state\",\"type\":\"custom_attribute\",\"value\":\"CA\"}]]]",
"name": "California Visitors",
"project_id": {{projectId}}
}Create "Mobile Web Users" audience
Create an audience named "Mobile Web Users" where the is_mobile_user attribute's value is true. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_mobile_user\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Mobile Web Users",
"project_id": {{projectId}}
}Create "Mobile App Users" audience
Create an audience named "Mobile App Users" where the is_mobile_app attribute's value is true. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\",{\"name\":\"is_mobile_app\",\"value\":true,\"match_type\":\"exact\",\"type\":\"custom_attribute\"}]]]",
"name": "Mobile App Users",
"project_id": {{projectId}}
}Create "QA Team 1" audience
Create an audience named "QA Team 1" where the is_qa attribute is true and the qa_team attribute's value is 1. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\", {\"value\": true,\"type\": \"custom_attribute\",\"name\": \"is_qa\"}]],[\"or\",[\"or\",{\"name\":\"qa_team\",\"type\":\"custom_attribute\",\"value\":\"1\"}]]]",
"name": "QA Team 1",
"project_id": {{projectId}}
}Create "QA Team 2" audience
Create an audience named "QA Team 2" where the is_qa attribute is true and the qa_team attribute's value is 2. Click Send Request in Visual Studio Code.
{{projectId}} is defined in the settings.json file. See the Configure API step for details.
This API corresponds to the following in the UI:
{
"conditions": "[\"and\",[\"or\",[\"or\", {\"value\": true,\"type\": \"custom_attribute\",\"name\": \"is_qa\"}]],[\"or\",[\"or\",{\"name\":\"qa_team\",\"type\":\"custom_attribute\",\"value\":\"2\"}]]]",
"name": "QA Team 2",
"project_id": {{projectId}}
}