Skip to main content

UC-014 — Compliance and Opt-out (GDPR)

Goal
Manage opt-out requests and contact deletion in GDPR compliance
Channel
All (SMS, RCS, WhatsApp)
Estimated time
15 minutes

Real-world scenarios​

  • FashionOutlet — GDPR Art. 17 request: A customer sends an email asking for their data to be deleted. Within 30 days the operator removes them from all lists and deletes their contact record, the part of the request that the contacts API covers (see Step 3).
  • TelcoMobile — Opt-out management: A user replies "STOP" to a promotional SMS. The system records the SMS opt-out on the contact, removes them from marketing lists and adds them to the exclusion list.
  • ClinicaSalute — Unreachable contact cleanup: After a campaign, the marketing team removes all contacts with permanent ERROR status to keep lists clean and reduce costs.

Prerequisites​

Before you begin, make sure you have:

  • Active API Key → How to get one
  • Contact ID or phone number to search
No simulation mode

The contacts API has no simulation or dry-run mode: DELETE /contacts/list/contacts and DELETE /contacts take effect immediately, and a deleted contact cannot be restored. Unknown body fields such as "simulation" are ignored. These calls use no credit: try the flow first on a contact you created for the purpose.

Opt-out and deletion flow​

The diagram illustrates the complete opt-out request handling flow: contact search, lookup of its lists, list removal, permanent deletion and confirmation.

Step 1 — Search for the contact by phone number​

When you receive an opt-out request, search for the contact in the system by its phone number, in E.164 format with the + URL-encoded as %2B:

curl -X GET "https://api.qlara.ai/api/partner-gateway/contacts?phoneNumber=%2B393471234567" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Contact found​

{
"data": [
{
"id": 20481,
"fullName": "Marco Bianchi",
"firstName": "Marco",
"lastName": "Bianchi",
"phoneNumbers": ["+393471234567"],
"mobilePhoneNumber": "+393471234567",
"listIds": [1201, 1202, 1203]
}
],
"page": 0,
"limit": 10,
"totalCount": 1,
"totalPages": 1
}
Note the id

The contact's id field will be needed for the following steps. If more than one contact has the number (the API does not reject duplicates), repeat Steps 2 and 3 for each of them. Do not take the lists to clean from listIds: it can also contain lists deleted in the meantime, which Step 2 would reject.

Step 2 — Remove the contact from all lists​

Find the lists that contain the contact with GET /contacts/list: with contactIds it returns the lists of your account that the contact belongs to, without the deleted ones, and isTest=false also leaves out the test lists.

curl -X GET "https://api.qlara.ai/api/partner-gateway/contacts/list?contactIds=20481&isTest=false&limit=1000" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Lists of the contact​

{
"data": [
{ "id": 1201, "name": "Clienti attivi" },
{ "id": 1202, "name": "Newsletter marketing" },
{ "id": 1203, "name": "Promo stagionali" }
],
"page": 0,
"limit": 1000,
"totalCount": 3,
"totalPages": 1
}

Then remove the contact from all of them in one call, passing their ids in listIds:

# Remove from "Clienti attivi", "Newsletter marketing" and "Promo stagionali"
curl -X DELETE "https://api.qlara.ai/api/partner-gateway/contacts/list/contacts" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"listIds": [1201, 1202, 1203],
"contactIds": [20481]
}'

Response — Removed from lists​

true

There is no need to repeat the call for each list: all the lists in listIds are covered at once. The lists must be active lists of your account and the contact must be a member of each of them: an unknown, deleted or test list makes the call answer 404 before anything is removed, while a list the contact does not belong to makes it answer 404 after the lists processed before it have already been cleaned. Taking the lists from GET /contacts/list avoids both cases.

Behind the scenes — What list removal does
  1. Memberships: DELETE /contacts (Step 3) also removes all the contact's list memberships, without the list-removal events of this step. For a full erasure, Step 2 is therefore optional; it is the step that matters for an opt-out that keeps the contact (see Variants).
  2. Audit trail: The platform keeps no record of list removals or deletions that the API can read: record the request (date, contact ID, lists) in your own system, as the "Record audit log" step of the diagram does. Each removal from a list also starts any active automation set to run when a contact is removed from that list, and such an automation can send the person a message or an email: check or pause those automations before handling an opt-out.
  3. Campaigns in progress: Removing the contact from a list keeps it out of the campaigns whose messages have not been prepared yet. A campaign whose messages are already being prepared or sent may still reach the contact.
  4. GDPR timelines: The European Regulation (Art. 17) allows 30 days to complete the deletion. However, best practice is to proceed with the deletion as soon as possible.

Step 3 — Delete the contact​

After removing the contact from all lists, proceed with permanent deletion:

curl -X DELETE "https://api.qlara.ai/api/partner-gateway/contacts?ids=20481" \
-H "X-Api-Key: YOUR_API_KEY"

Response — Contact deleted​

true
Permanent deletion

Contact deletion is irreversible. DELETE /contacts removes the contact record (name, phone numbers, email addresses, custom fields, consents) together with its list memberships. It does not remove the message and delivery history, which the API keeps (GET /messages/history still returns the number as a destination), the inbox conversations, the destinations of campaigns already sent, or the contact exports already generated, which stay downloadable until they expire after 7 days: no Partner Gateway endpoint deletes these. Make sure you have completed the necessary audit and backup operations before proceeding. Always pass the contact in ids: the notIds parameter works the other way round and deletes every contact in the account except the listed ones and the test contacts.

Step 4 — Verify the deletion​

Confirm that the contact no longer exists in the system. This search is the reliable check, because DELETE /contacts answers true even when it deleted nothing:

curl -X GET "https://api.qlara.ai/api/partner-gateway/contacts?phoneNumber=%2B393471234567" \
-H "X-Api-Key: YOUR_API_KEY"

Response — No results​

{
"data": [],
"page": 0,
"limit": 10,
"totalCount": 0,
"totalPages": 0
}

Expected result​

StepActionResult
1GET /contacts?phoneNumber=...Contact found, with its id
2GET /contacts/list?contactIds={id}&isTest=false + DELETE /contacts/list/contactsContact removed from all its lists
3DELETE /contacts?ids={id}Contact record permanently deleted
4GET /contacts?phoneNumber=...totalCount: 0, deletion confirmed

Complete end-to-end example​

Here is the full FashionOutlet scenario for a GDPR Art. 17 request:

#!/bin/bash
# Complete GDPR opt-out script for FashionOutlet

API_KEY="YOUR_API_KEY"
BASE_URL="https://api.qlara.ai/api/partner-gateway"
PHONE="+393471234567"
PHONE_ENCODED="%2B393471234567"

echo "=== GDPR Opt-out Request ==="
echo "Request date: $(date -Iseconds)"
echo "Number: ${PHONE}"

# 1. Search for the contact
CONTACT=$(curl -s -X GET "${BASE_URL}/contacts?phoneNumber=${PHONE_ENCODED}" \
-H "X-Api-Key: ${API_KEY}")

CONTACT_ID=$(echo "$CONTACT" | jq -r '.data[0].id')
TOTAL=$(echo "$CONTACT" | jq -r '.totalCount')

if [[ "$TOTAL" == "0" || "$CONTACT_ID" == "null" ]]; then
echo "Contact not found. No action needed."
exit 0
fi

echo "Contact found: ${CONTACT_ID}"

# 2. Remove the contact from all its active lists in one call
LIST_IDS=$(curl -s -X GET "${BASE_URL}/contacts/list?contactIds=${CONTACT_ID}&isTest=false&limit=1000" \
-H "X-Api-Key: ${API_KEY}" | jq -c '[.data[].id]')

if [[ "$LIST_IDS" != "[]" ]]; then
echo "Removing from lists: ${LIST_IDS}"
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X DELETE "${BASE_URL}/contacts/list/contacts" \
-H "X-Api-Key: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{"listIds": '"${LIST_IDS}"', "contactIds": ['"${CONTACT_ID}"']}')

if [[ "$STATUS" != "200" ]]; then
echo "List removal failed (HTTP ${STATUS}). Manual verification needed."
exit 1
fi
fi

# 3. Delete the contact
echo "Deleting contact: ${CONTACT_ID}"
curl -s -X DELETE "${BASE_URL}/contacts?ids=${CONTACT_ID}" \
-H "X-Api-Key: ${API_KEY}" > /dev/null

# 4. Verify
VERIFY=$(curl -s -X GET "${BASE_URL}/contacts?phoneNumber=${PHONE_ENCODED}" \
-H "X-Api-Key: ${API_KEY}" | jq -r '.totalCount')

if [[ "$VERIFY" == "0" ]]; then
echo "Contact deleted."
else
echo "WARNING: contact still present. Manual verification needed."
fi

Variants​

Marketing-only opt-out (keep contact)​

If the user only wants to stop receiving promotional messages, keep the contact for transactional communications and record the opt-out in its consents, for the channel the request came from:

curl -X PUT "https://api.qlara.ai/api/partner-gateway/contacts/20481" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"consents": {"sms_status": "OPTOUT", "sms_status_date": "2026-10-09T08:15:30Z"}}'

The update changes only the channels in consents, each dated with its <status>_date or, without one, with the time of the request; the other consents and fields of the contact stay as they are. The platform then copies the contact's consents to the other contacts of your account with the same main email (or, for a contact without one, the same mobile number).

Recording the consent does not stop the sends by itself: SMS, RCS and WhatsApp campaigns reach every member of their lists. Also remove the contact from the marketing lists as in Step 2, and check promotional audiences with the consent filters: GET /contacts/list/{listId}/contacts?smsStatus=OPTOUT returns the members of a list who opted out of SMS.

Bulk cleanup of unreachable contacts​

After a campaign, remove the contacts with permanent errors from your lists with DELETE /contacts/list/contacts. Every contact in contactIds must be a member of every list in listIds, so send one call per list with only the contacts that belong to it (find them with GET /contacts/list/{listId}/contacts), or one call per contact with its own lists, as in Step 2. If a contact is not in one of the lists, the call answers 404 after removing the pairs processed before it, list by list and contact by contact; those stay removed, so repeating the same call fails again: send only the pairs that are left.

Common errors​

404 Not Found — List or contact not found in Step 2​

{ "status": "fail", "data": "Resource not found." }

DELETE /contacts/list/contacts answers 404 when one of the listIds is not an active list of your account (unknown, deleted or a test list), when the contact does not exist (for example it has already been deleted) or is a test contact, or when it is not a member of one of the lists. The message does not say which.

Solution: Take the lists from GET /contacts/list?contactIds={id}&isTest=false, as in Step 2. A test contact (isTest: true) can be neither removed from a list by its ID nor deleted through the API.

DELETE /contacts answers true even when nothing was deleted​

DELETE /contacts never answers 404 or 409. It answers 200 with true even when it deleted nothing: unknown or already deleted IDs and IDs of other accounts are ignored, and test contacts are never deleted. It answers 400 only when neither ids nor notIds is given, or when the one used is empty, has more than 200 IDs or contains a value that is not a positive integer.

Solution: Confirm the erasure with the search of Step 4: GET /contacts?phoneNumber=... must return totalCount: 0.

Next steps​

References​