API Reference
This section is a comprehensive reference to the .Net SDK and the methods that can be called to initialize, manage, and interact with consent data.
Always use CMPSDK.sharedInstance to refer to the OneTrust SDK. Please verify the SDK successfully initializes before calling any of these methods. For more information, see Initialize the SDK.
Retrieve data to build your UI
Method | Data Retrieved |
---|---|
CMPSDK.sharedInstance.dataForBanner(); | JSON to build banner. |
CMPSDK.sharedInstance.dataForPreferenceCenter(); | JSON to build preference center. |
CMPSDK.sharedInstance.groupsDataForUIBinding(); | JSON to populate preference center with Category/Group data. |
CMPSDK.sharedInstance.getSavedConsentProfile() | JSON object with the saved state of the categories. |
CMPSDK.sharedInstance.dataForVendorList(); | JSON to build vendor list (TCF 2.0 use cases only). |
Handling user interactions
Banner
Method Name | Usage |
---|---|
CMPSDK.sharedInstance.bannerAccept(); | User has clicked the Accept All button on banner. |
CMPSDK.sharedInstance.bannerRejectAll(); | User has clicked the Reject All button on banner. |
CMPSDK.sharedInstance.bannerClose(); | User has closed the banner. |
Preference Center
When updating consent for individual categories, the Preference Center works on a "stage and commit" model. You will update the consent values for each category as it is toggled, but changes will not be saved until the Save function is called.
Method Name | Usage |
---|---|
CMPSDK.sharedInstance.updateConsentValueForCategory(string category, bool consentValue); | User has adjusted a consent toggle. |
CMPSDK.sharedInstance.saveChanges(); | User has saved changes in the preference center. |
CMPSDK.sharedInstance.preferenceCenterAcceptAll(); | User has accepted all in the preference center. There is no need to save after this is called. |
CMPSDK.sharedInstance.preferenceCenterRejectAll(); | User has rejected all in the preference center. There is no need to save after this is called. |
Vendor List
When updating consent for individual vendors, the vendor list works on a "stage and commit" model. You will update the consent values for each vendor consent as it is toggled, but changes will not be saved until the Save function is called.
Method Name | Usage |
---|---|
CMPSDK.sharedInstance.updateConsentValueForVendor(string vendorId, bool consentValue); | User has adjusted a consent toggle. |
CMPSDK.sharedInstance.updateConsentValueForVendorLegitimateInterest(string vendorId, bool consentValue); | User has adjusted a LegitimateInterest toggle. |
CMPSDK.sharedInstance.saveChanges(); | User has saved changes in the preference center. |
CMPSDK.sharedInstance.vendorsAcceptAll(); | User has accepted all in the vendor list. There is no need to save after this is called. |
CMPSDK.sharedInstance.vendorsRejectAll(); | User has rejected all in the vendor list. There is no need to save after this is called. |
Multi Profile Consent
The following methods can be used to support multi profile consent for your application if you allow multiple user profiles to use one login.
Method Name | |
---|---|
CMPSDK.sharedInstance.userProfiles() | Call this to list the user profiles. |
CMPSDK.sharedInstance.switchUserProfile(DSID) | Use the following method to allow users to switch profiles so that consent profile of the current user is saved and profile for the new user is retrieved from user defaults. |
CMPSDK.sharedInstance.renameProfile(from: old_profile_id, to: new_profile_ID) | Use the following method to allow you to rename a user's profile. |
CMPSDK.sharedInstance.deleteProfile(dsid) | Use the following method to delete a user's profile. |
userProfiles Payload
// Returns array of profiles. Only 1 profile can be Active.
[
{
"OneTrust_ConsentLoggingIdentifier": "545bd599-51d6-401e-af1c-17c0611ad81f",
"OneTrust_UID_isAnonymous": true,
"OneTrust_lastInteraction": "Preference Center - Confirm",
"OneTrust_lastConsentDate": 637902346597025080,
"isActiveProfile": true
},
{
"OneTrust_ConsentLoggingIdentifier": "9898db3-51d6-401e-af1c-17c0611ad37d",
"OneTrust_UID_isAnonymous": true,
"OneTrust_lastInteraction": "Banner - Accept All",
"OneTrust_lastConsentDate": 637902346597025080,
"isActiveProfile": false
}
]
// If you want to take lastConsentDate to a formatted date...
DateTime lastConsentDate = new DateTime(long.Parse(OneTrust_lastConsentDate));
System.Diagnostics.Debug.WriteLine(lastConsentDate.ToUniversalTime().ToString("F"));
Fetch CMP API Data*
The CMP API is split into three parts to improve the performance. The initial API call fetchs only Banner UI data and the rest of the data is fetched whenever the user navigates to a particular screen. See below the list of methods to fetch individual API data:
Method | Data Fetched |
---|---|
CMPSDK.sharedInstance.FetchBannerCmpApiData() | Fetch Banner UI data. |
CMPSDK.sharedInstance.FetchPreferencesCmpApiData() | Fetch Preference Center UI data. |
CMPSDK.sharedInstance.dataForVendorList() | Fetch Vendor UI data. If Preference Center data is not fetched before calling this method, it will first fetch PC data before fetching Vendor data. |
*These changes will be available from 202503.2.0 release for MAUI/.Net SDK only.
Updated 7 days ago