Example of implementation
Example using Resource loader API
This guide provides a practical use case example for implementing the Feature Experimentation Resource Loader API. It demonstrates how to create a complete feature flag campaign with variations, targeting rules, and goals using a single API call.
Overview
The Resource Loader API allows you to create, update, or delete multiple related resources (projects, campaigns, flags, goals, targeting keys, variation groups, and variations) in a single HTTP POST request. This approach ensures data consistency and simplifies the creation of complex feature experimentation setups.
API Endpoint
POST https://resource-loader-api.abtasty.com/v1/feature-exp/resource-loaderHeaders
Content-Type: application/json
Authorization: Bearer YOUR_API_TOKEN (Remote Control API)Use Case Example: Creating a Feature Flag A/B Test
This example demonstrates creating a complete feature experimentation setup that includes:
A project to organize campaigns
Feature flags for controlling features
Targeting keys for audience segmentation
Goals for conversion tracking
An A/B test campaign with multiple variations
Variation groups with targeting rules
Complete Resource Loader Payload
Step-by-Step Implementation
Step 1: Prepare Your Payload
Create a JSON file (e.g., feature-campaign-setup.json) with your resource loader configuration. Use the $_ref notation to reference resources created earlier in the same request.
Step 2: Make the API Request
Using cURL
Using JavaScript (Fetch API)
Step 3: Handle the Response
The API will return a response containing the IDs of all created resources:
Advanced Use Cases
Updating Existing Resources
To update an existing campaign, use the edit action and provide the resource ID:
Deleting Resources
To delete a resource:
Using Reference Injection
You can inject existing resource IDs from command-line flags when using the AB Tasty CLI:
Then reference them in your JSON:
Key Concepts
1. Reference System ($_ref)
$_ref)Each resource uses a unique reference identifier that can be used to link resources within the same request:
2. Variation Groups and Targeting
Variation groups define how users are segmented and which variations they see:
3. Flag Modifications
Variations modify feature flag values to deliver different experiences:
4. Traffic Allocation
Allocations must sum to 100% within each variation group:
Targeting Operators
Use these operators in your targeting rules:
EQUALS
Exact match
"value": "premium"
IN
In
"value": "free"
CONTAINS
Contains substring
"value": "prod"
Flag Types
Feature flags support multiple data types:
boolean
True/false values
true, false
string
Text values
"green", "v2"
number
Numeric values
42, 3.14
Goal Types
Track different conversion events:
screenview
Screen/page views
Track navigation
event
Custom events
Button clicks, interactions
transaction
Purchase events
E-commerce conversions
Best Practices
Use Meaningful References: Choose descriptive
$_refnames that clearly indicate what each resource represents (e.g.,premium_users_campaigninstead ofc1).Define Dependencies First: Create projects, flags, and targeting keys before campaigns that use them.
Validate Allocations: Always ensure variation allocations sum to exactly 100% within each variation group.
Start with Paused Campaigns: Create campaigns in a paused state, then activate after verification.
Test Targeting Rules: Verify targeting logic with test users before full deployment.
Use Descriptive Names: Give clear names to variations that describe what they're testing (e.g., "New Checkout Flow" not "Variant A").
Document Flag Values: Include descriptions for all flags explaining their purpose and expected values.
Handle Errors Gracefully: Check the response status for each resource and implement retry logic for transient failures.
Version Your Payloads: Keep your resource loader JSON files in version control to track changes over time.
Monitor Flag Usage: Track which flags are actively used in campaigns before deleting them.
Support
For questions or issues with the Resource Loader API, consult the main Resource Loader documentation or contact AB Tasty support.
Last updated
Was this helpful?

