By using the anonymization function of the API, text responses in the results or participants in participant lists can be anonymized. In this way, the data is made unrecognizable.
Anonymize results
This method can be used to anonymise text results using the same search parameters as in the results search (/api/v2/results). The texts of the results corresponding to this search are replaced by the text string ‘** anonymised **’. A maximum of 1.000 data records can be anonymised per query.
URL |
/api/v2/results/anonymize |
||||||||||||||||||
Method |
POST |
||||||||||||||||||
Parameter |
memberid, searchstring, resultid |
||||||||||||||||||
Return |
Result Objekte als JSON |
||||||||||||||||||
Return values |
|
Example: Anonymise all text responses to a survey
<?php
// Anonymise all text responses to a survey
// anonymizeResultsAll.php
// v1.0.1
// Insert access token here
$accessToken = 'YOUR_ACCESS_TOKEN';
// Insert survey ID here
$surveyid = 'YOUR_SURVEYID';
// API-URLs
$membersApiUrl = 'https://app.easy-feedback.com/api/v2/members?surveyid=' . $surveyid;
$anonymizeApiUrl = 'https://app.easy-feedback.com/api/v2/results/anonymize';
// Function for anonymising the results
function anonymizeResults($accessToken, $anonymizeApiUrl, $memberid)
{
$apiUrl = $anonymizeApiUrl . '?memberid=' . $memberid;
$ch = curl_init($apiUrl);
// Configure cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/x-www-form-urlencoded',
));
$response = curl_exec($ch);
// Display the result as JSON
if ($response === false) {
$error = 'Error in the cURL request for MemberID ' . $memberid . ': ' . curl_error($ch);
curl_close($ch);
return ['success' => false, 'error' => $error];
} else {
$jsonData = json_decode($response, true);
curl_close($ch);
if ($jsonData === null) {
$error = 'Error decoding the JSON response for MemberID ' . $memberid;
return ['success' => false, 'error' => $error];
} else {
// Check whether anonymisation was successful
$anonymizedCount = 0;
foreach ($jsonData as $result) {
if (isset($result['Answertext']) && $result['Answertext'] === '** anonymized **') {
$anonymizedCount++;
}
}
return ['success' => true, 'anonymizedCount' => $anonymizedCount];
}
}
}
// API query for members
$chMembers = curl_init($membersApiUrl);
curl_setopt($chMembers, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chMembers, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
));
$responseMembers = curl_exec($chMembers);
if ($responseMembers === false) {
echo 'Error in the cURL request for members: ' . curl_error($chMembers);
exit;
}
$jsonDataMembers = json_decode($responseMembers, true);
if ($jsonDataMembers === null || !isset($jsonDataMembers['results'])) {
echo 'Error decoding the JSON response for members.';
echo '<br><br>JSON answer: <pre>' . json_encode($jsonDataMembers, JSON_PRETTY_PRINT)."</pre>";
exit;
}
// Enquiry counter and time of the last enquiry
$requestCounter = 0;
$anonymizedMembers = 0;
$lastRequestTime = time();
foreach ($jsonDataMembers['results'] as $member) {
// Check whether one minute has passed since the last enquiry
if (time() - $lastRequestTime >= 60) {
$requestCounter = 0; // Resetting the enquiry counter
$lastRequestTime = time(); // Updating the time of the last enquiry
}
// Anonymising the results
$result = anonymizeResults($accessToken, $anonymizeApiUrl, $member['Id']);
if ($result['success']) {
$anonymizedMembers += $result['anonymizedCount'];
} else {
echo 'Error in the anonymisation for MemberID ' . $member['Id'] . ': ' . $result['error'] . PHP_EOL;
}
// Increasing the enquiry counter
$requestCounter++;
// Check whether the maximum number of requests per minute has been reached
if ($requestCounter >= 60) {
// Wait until one minute has passed since the last enquiry
while (time() - $lastRequestTime < 60) {
usleep(100000); // Wait for 100 milliseconds (0.1 seconds)
}
$requestCounter = 0; // Resetting the request counter after waiting
$lastRequestTime = time(); // Updating the time of the last enquiry
}
}
// Close cURL connection
curl_close($chMembers);
// Output of successful anonymisations
echo 'Successfully anonymised results: ' . $anonymizedMembers;
?>
Example: Anonymise a single text response with the Result ID X
<?php
// Anonymise a single text response with the Result ID X
// anonymizeOneTextAnswersByResultId.php
// v1.0.1
// Insert access token here
$accessToken = 'YOUR_ACCESS_TOKEN';
// Insert member ID here
$memberid = 'YOUR_MEMBERID';
// Insert Result ID here
$resultid = 'YOUR_RESULTID'; # z.B.: text_123456789
$apiUrl = 'https://app.easy-feedback.com/api/v2/results/anonymize?memberid=' . $memberid . '&resultid=' . $resultid;
$ch = curl_init($apiUrl);
// Configure cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/x-www-form-urlencoded',
));
$response = curl_exec($ch);
// Display the result as JSON
if ($response === false) {
echo 'Error in the cURL request: ' . curl_error($ch);
} else {
$jsonData = json_decode($response, true);
if ($jsonData === null) {
echo 'Error decoding the JSON response.';
} else {
echo 'JSON response: <pre>' . json_encode($jsonData, JSON_PRETTY_PRINT)."</pre>";
}
}
// Close cURL connection
curl_close($ch);
?>
Anonymise participants in participants list
There are two different options for anonymizing participants in participant lists:
- participantlistid: This method is used to specifically address a list of participants. The anonymization takes place in the global participant list, and if the participant list is assigned to one or more surveys, the participants are also anonymized under e-mail invitations.
- surveyid: With this method, all participant lists that are assigned to a survey will be anonymized. In addition, these participant lists will also be anonymized under the global participant lists.
As soon as anonymization is executed, the following fields within the participant list are anonymized:
* Email
* Firstname
* Lastname
* Value 1-25
Anonymization via participantlistid
URL |
/api/v2/participants/users/anonymize/[ParticipantListId] |
||||||||||||||||||||||||||||||
Method |
POST |
||||||||||||||||||||||||||||||
Parameter |
page, limit |
||||||||||||||||||||||||||||||
Return |
List of the IDs of the anonymised participants as JSON |
||||||||||||||||||||||||||||||
Return values |
|
Anonymization via surveyid
URL |
/api/v2/participants/users/anonymize/[SurveyId] |
||||||||||||||||||||||||||||||
Methode |
POST |
||||||||||||||||||||||||||||||
Parameter |
– |
||||||||||||||||||||||||||||||
Return |
Survey Participant objects as JSON |
||||||||||||||||||||||||||||||
Return values |
|