UC-013 — Advanced Contact Segmentation
- Goal
- Segment contacts with advanced filters to create targeted lists
- Channel
- All
- Estimated time
- 30 minutes
Real-world scenarios
- TurismoVeneto — Segment by region: Filter 20,000 contacts by region of residence and create separate lists for Lombardy, Veneto and Emilia-Romagna for geo-targeted promotions.
- LuxuryStore — VIP list: Identify customers with total spending above 5,000 EUR and create a VIP list for exclusive previews and private event invitations.
- FreshMarket — Filter by last purchase: Select customers who haven't purchased in over 90 days for a re-engagement campaign with discount coupons.
Segmentation flow
The diagram shows the flow: from the full list, multiple filters (region, attributes, date) are applied to create segmented lists ready for campaigns.
Prerequisites
- Active API Key with contact management permissions
- Contacts imported into the platform (see UC-011)
- At least one existing contact list with populated custom fields
Step 1 — Retrieve contacts with filters
Query the contacts with the filters supported by GET /contacts, here only the reachable ones (isValid=true). The region is not a query parameter: in this example it is stored in customField1, with the total spent in customField2 and the last purchase date in customField3 (set at import or with PUT /contacts/{id}), and you select on these fields in your code. To keep only the contacts who opted in to the campaign's channel, add its consent filter, such as smsStatus=OPTIN.
curl -X GET "https://api.qlara.ai/api/partner-gateway/contacts?isValid=true&page=0&limit=50" \
-H "X-Api-Key: YOUR_API_KEY"
Response — Filtered contacts
{
"data": [
{
"id": 30112,
"fullName": "Marco Rossi",
"firstName": "Marco",
"lastName": "Rossi",
"phoneNumbers": ["+393471234567"],
"emailAddresses": ["marco.rossi@email.it"],
"mobilePhoneNumber": "+393471234567",
"isValidMobilePhoneNumber": true,
"city": "Milano",
"customField1": "Lombardia",
"customField2": "1250.00",
"customField3": "2026-03-15"
},
{
"id": 30113,
"fullName": "Laura Bianchi",
"firstName": "Laura",
"lastName": "Bianchi",
"phoneNumbers": ["+393489876543"],
"emailAddresses": ["laura.bianchi@email.it"],
"mobilePhoneNumber": "+393489876543",
"isValidMobilePhoneNumber": true,
"city": "Bergamo",
"customField1": "Lombardia",
"customField2": "6800.00",
"customField3": "2026-01-10"
}
],
"page": 0,
"limit": 50,
"totalCount": 18640,
"totalPages": 373
}
Behind the scenes — Available filters and query logic
- Standard filters:
search(case-insensitive substring offullName,firstName,lastName,mainEmailormobilePhoneNumber),gender,isValid,communicationSupported,isTest,phoneNumber(exact, in E.164 with the+sent as%2B),email(exact, ignoring case),listIdsandnotListIdscan be filtered directly as query parameters. Filtering byid,lastContactTypeorlastCampaignTypeis not supported and answers400; to read a single contact, useGET /contacts/{id}. - Custom fields:
customField1,customField2andcustomField3, likecityandtags, are returned with every contact but are not query parameters: select on them client-side, then add the selected contacts to a list withPOST /contacts/list/contacts(Steps 2 and 3). - Pagination: Use
page(starting at 0) andlimitto paginate large result sets; the response carriestotalCountandtotalPages. The maximum forlimitis 1000. - Sorting: Use
sortBy=field&sortOrder=asc|descto sort results (by default byfullName, ascending). - Combining filters: All filters use logical AND, except
listIds,notListIdsandsortPriorityListId: a call can use only one of them, and combining two answers400. For OR logic, or for the contacts of one list that are not in another, run several queries and combine the results client-side.
Step 2 — Create a segmented list
Create a new list for the identified segment.
curl -X POST https://api.qlara.ai/api/partner-gateway/contacts/list \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "VIP Lombardia - Spesa > 5000 EUR",
"description": "Clienti lombardi con spesa totale superiore a 5000 EUR"
}'
Response — List created
{
"id": 912,
"name": "VIP Lombardia - Spesa > 5000 EUR",
"description": "Clienti lombardi con spesa totale superiore a 5000 EUR",
"companyId": 4618,
"numContact": 0,
"isTest": false,
"isDeleted": false,
"lastCampaignDate": null,
"lastCampaignType": null,
"createdAt": "2026-04-09 09:00:00.418+0000",
"updatedAt": "2026-04-09 09:00:00.418+0000"
}
Step 3 — Add contacts to the segmented list
Add the filtered contacts to the new list using their IDs.
curl -X POST https://api.qlara.ai/api/partner-gateway/contacts/list/contacts \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"listIds": [912],
"contactIds": [30113, 30127, 30188, 30241, 30302]
}'
Response — Contacts added
[30113, 30127, 30188, 30241, 30302]
The response lists the IDs of the contacts added to the list, one per new membership; contacts that were already in the list are left out.
For large lists, automate the process server-side: retrieve all filtered contacts with pagination, collect the IDs and send them in batches to the list. The API sets no cap on the number of contactIds, but each call is processed as a whole: send the IDs of one page of GET /contacts (up to 1,000, the maximum limit) per call rather than one huge array.
Expected result
| Step | Action | Result |
|---|---|---|
| 1 | GET /contacts?isValid=true | Reachable contacts, Lombardy ones selected on customField1 |
| 2 | POST /contacts/list | New segmented list created |
| 3 | POST /contacts/list/contacts | VIP contacts added to the list |
Complete end-to-end example
# 1. Retrieve the reachable contacts (with pagination)
CONTACTS=$(curl -s -X GET \
"https://api.qlara.ai/api/partner-gateway/contacts?isValid=true&page=0&limit=1000" \
-H "X-Api-Key: YOUR_API_KEY")
# 2. Filter client-side: Lombardy (customField1) with spending > 5000 EUR (customField2)
VIP_IDS=$(echo "$CONTACTS" | jq -c '[.data[] | select(.customField1 == "Lombardia" and ((.customField2 | tonumber?) // 0) > 5000) | .id]')
echo "VIP IDs: $VIP_IDS"
# 3. Create the segmented list
LIST_ID=$(curl -s -X POST https://api.qlara.ai/api/partner-gateway/contacts/list \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "VIP Lombardia - Spesa > 5000 EUR",
"description": "Segmento VIP per campagna esclusiva"
}' | jq -r '.id')
echo "List ID: $LIST_ID"
# 4. Add contacts to the list
curl -s -X POST https://api.qlara.ai/api/partner-gateway/contacts/list/contacts \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d "{
\"listIds\": [${LIST_ID}],
\"contactIds\": ${VIP_IDS}
}" | jq .
Variants
Segmentation by inactivity (re-engagement)
Filter contacts who haven't purchased in over 90 days, comparing client-side the last purchase date stored in customField3 (format yyyy-MM-dd):
curl -s -X GET "https://api.qlara.ai/api/partner-gateway/contacts?isValid=true&page=0&limit=1000" \
-H "X-Api-Key: YOUR_API_KEY" | jq -c '[.data[] | select((.customField3 // "") != "" and .customField3 < "2026-01-09") | .id]'
Remove a contact from a list
If a contact should no longer belong to a segment:
curl -X DELETE https://api.qlara.ai/api/partner-gateway/contacts/list/contacts \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"listIds": [912],
"contactIds": [30302]
}'
Common errors
Unfiltered results — Unknown filter
GET /contacts does not reject query parameters it does not recognize: a filter such as region=Lombardia or customField1=Lombardia is ignored, and the response contains every contact the other filters match.
Solution: Use only the standard filters listed under Step 1. For city, tags and the custom fields, select client-side and add the selected contacts to the list with POST /contacts/list/contacts.
404 Not Found — Contact or list not found
{
"status": "fail",
"data": "Resource not found."
}
POST /contacts/list/contacts answers 404 when one of the listIds is not a list of your account, or one of the contactIds is not a contact of your account or is a test contact. Nothing is added, and the message does not say which ID is missing.
Solution: The contact may have been deleted, may not exist or may be a test contact (isTest: true), which cannot be added to a list by its ID. Verify the IDs with GET /contacts/{id} and GET /contacts/list/{id} before adding to the list.
401 Unauthorized — Missing or invalid API Key
{
"error": "Invalid API Key"
}
Solution: Verify that the X-Api-Key header is present and that the key is active in the platform dashboard.
Next steps
- UC-011 — Manage Contacts and Lists: Import contacts from CSV and VCard
- UC-001 — Bulk SMS Campaign: Use the segmented list in an SMS campaign
- UC-008 — Bulk WhatsApp Campaign: Send to the VIP list via WhatsApp
- UC-014 — Compliance Opt-out GDPR: Manage opt-out and GDPR compliance
References
- API Reference — Contacts: Full contact endpoint documentation
- Contacts and Lists Guide: Best practices for contact management
- Authentication Guide: Details on API Key and Basic Auth