Data consistency with entity tag
In order to manage concurrent updates of a profile from many devices or websites, use eTag.
When obtaining profile details from the services you can find an eTag in the CMPResult
object. It describes what version of the server data you received.
When you want to update this data, pass the same eTag with the new profile details. If the server data changes before your next update the services don’t allow the modification until you obtain the most recent version of the data and pass the correct eTag with the next update. This way you can keep consistency of the data across many devices.
Get profile
[client.services.profile getProfileForProfileID:@"<PROFILE-ID>" completion:^(CMPResult<CMPProfile *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.profile.getProfile(profileID: "") { (result) in
if let err = result.error {
// error occurred
} else if let obj = result.object {
// success
}
}
Query profiles
// query profiles where there is a given value under the given key
CMPQueryElements *e1 = [[CMPQueryElements alloc] initWithKey:@"key" element:CMPQueryElementEqual value:@"value"];
[client.services.profile queryProfilesWithQueryElements:[NSArray arrayWithObjects:e1, nil] completion:^(CMPResult<NSArray<CMPProfile *> *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.profile.queryProfiles(queryElements: [.init(key: "email", element: .contains, value: "new")]) { (result) in
if let err = result.error {
// error occurred
} else if let obj = result.object {
// success
}
}
Patch profile
Applies a patch for a user profile.
This method doesn’t erase previous profile details with different keys.
[client.services.profile patchProfileWithProfileID:@"<PROFILE-ID>" attributes:@{@"email" : @"[email protected]"} eTag:nil completion:^(CMPResult<CMPProfile *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.profile.patchProfile(profileID: "profileId", attributes: ["email" : "[email protected]"], eTag: nil) { (result) in
if let err = result.error {
// error occurred
} else if let obj = result.object {
// success
}
}
Update profile
Update a user profile providing a custom map of values that should be associated with it.
[client.services.profile updateProfileWithProfileID:@"<PROFILE-ID>" attributes:@{@"email" : @"[email protected]"} eTag:nil completion:^(CMPResult<CMPProfile *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.profile.updateProfile(profileID: "profileId", attributes: ["email" : "[email protected]"], eTag: nil) { (result) in
if let err = result.error {
// error occurred
} else if let obj = result.object {
// success
}
}