Change and delete consent
This page explains how to implement changing optional consent, re-consent, and deleting consent, which happen after the user has consented to the terms. To learn how to obtain terms consent for the first time, see Get terms and consent.
Change optional consent
When the user changes the consent for an optional item, for example on a settings screen, save only the changed items with SaveConsentAsync().
- Use
GetTermsAsync()to receive theTermId,Version, andLanguageof the current terms and theItemIdandItemRevisionIdof the items. - Put only the items whose consent changes in
Items. If this is not the first consent, you do not need to include the required items again. - Pass
Agreedastrueif the user consents, orfalseif the user withdraws. - Call with a new idempotency key. A new
ApiCallContextis filled with a new idempotency key.
using System.Collections.Generic;
// doc: Current terms received with GetTermsAsync()
// marketingItem: Optional item whose consent the user withdrew
TermsSaveConsentResult result = await terms.SaveConsentAsync(new SaveConsentRequest
{
CompanyCode = companyCode, // Company code: the part before the first '.' of the App ID
ServiceCode = "SAMPLE",
SubjectKey = subjectKey, // same consent subject as in the status query
TermId = doc.TermId,
Version = doc.Version,
Language = doc.Language,
Channel = "APP",
Items = new List<ConsentItemRequest>
{
new ConsentItemRequest
{
ItemId = marketingItem.ItemId,
ItemRevisionId = marketingItem.ItemRevisionId,
Agreed = false, // Withdraw optional consent
},
},
}, new ApiCallContext());
switch (result)
{
case TermsSaveConsentResult.Success success:
// success.Data holds the consent status after saving.
break;
case TermsSaveConsentResult.RequiredConsentDeclined:
// Required items cannot be withdrawn.
break;
case TermsSaveConsentResult.Failure failure:
Debug.LogError($"[Terms] {failure.Problem.ExternalCode} (trace: {failure.Problem.TraceId})");
break;
case TermsSaveConsentResult.UnknownOutcome unknown:
Debug.LogWarning($"[Terms] Unknown outcome: {unknown.Code}");
break;
// Handle other results as in the response status table of Save consent.
default:
Debug.LogWarning($"Unhandled result: {result.GetType().Name}");
break;
}
When you withdraw consent for an optional item, the item Status in the consent status changes to Declined, and the consent history records it as Withdraw. Required items cannot be withdrawn, and passing false for a required item returns RequiredConsentDeclined. Handling by result case is the same as for Save consent.
If you need to control app features based on the consent for an optional item (for example, sending promotional notifications), check with GetConsentStatusAsync() that the Status of that item is Consented before you run the feature.
Re-consent
When the operator deploys items whose content changed as a re-consent request, the Status of those items in the consent status changes to ReconsentRequired for users who already consented, and Data.ReconsentRequired becomes true.
Re-consent has no separate method; follow steps 2 to 4 of Get terms and consent as they are. If Data.ReconsentRequired is true when you check the consent status, such as at app launch or login, show the terms consent screen again. Saved re-consent is recorded as Reconsent in the consent history.
If there is a scheduled deployment, NextChangeAt in the get terms response holds the time the next terms take effect. Use it to notify users of a terms change in advance.
Delete consent
EraseConsentsAsync
When the user deletes their account, delete the current consent of the consent subject. For deleting a Hive Axyl account, see Account deletion. Include consent deletion in your account deletion flow, and call it before you request account deletion.
Call parameters
| Field name | Type | Required | Description |
|---|---|---|---|
request | EraseConsentsRequest | Required | Request object. ArgumentNullException is thrown if it is null |
request.CompanyCode | string | Required | Company code. The part before the first . of the App ID |
request.ServiceCode | string | Required | Service code |
request.SubjectKey | string | Required | Identifier of the consent subject |
context | ApiCallContext? | Optional | Per-call settings object |
Call example
TermsEraseConsentsResult result = await terms.EraseConsentsAsync(new EraseConsentsRequest
{
CompanyCode = companyCode,
ServiceCode = "SAMPLE",
SubjectKey = subjectKey, // same consent subject as in the status query
});
switch (result)
{
case TermsEraseConsentsResult.Success:
// Proceed with account deletion.
break;
case TermsEraseConsentsResult.ServiceNotFound:
// Check the company code and the service code.
break;
case TermsEraseConsentsResult.Failure failure:
Debug.LogError($"[Terms] {failure.Problem.ExternalCode} (trace: {failure.Problem.TraceId})");
// The call can be repeated, so retry.
break;
case TermsEraseConsentsResult.UnknownOutcome unknown:
Debug.LogWarning($"[Terms] Unknown outcome: {unknown.Code}");
break;
// Safety net: unhandled results
default:
Debug.LogWarning($"Unhandled result: {result.GetType().Name}");
break;
}
Notes
- It returns
Successeven if there is no consent to delete, so you can call it repeatedly. - Only the current consent is deleted; consent history is not deleted. The deletion record is kept in the consent history as
Erase. - If you obtained consent both before and after login, delete the consent of the Device Key and the Player ID separately. They are different consent subjects.
- An idempotency key that a deleted consent subject used earlier cannot be used again. When you save consent again for the same consent subject after deletion, use a new idempotency key.