AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    Administration interface basicsDevelopers and adminsBusiness usersChangelogGlossary
  • Guides
    Welcome to Xperience by KenticoAdministration interface basicsCustomer journeysDigital marketingConfigurationDevelopmentArchitectureUpgrade to Xperience by Kentico
  • Training
    For AdminsFor Business usersFor DevelopersFor Solution architects
  • API Examples
    ConfigurationContent managementDevelopmentDigital marketing
  • Changelog
    Documentation updatesSecurity advisories
  1. Home
  2. Digital marketing
  3. Contact groups

Contact groups


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Dependency injection
    • Initialize required services
  • Contact groups
    • Create contact groups
    • Update contact groups
    • Update multiple contact groups
    • Delete contact groups

Dependency injection

Initialize required services

C#
// Initializes all services and provider classes used within
// the API examples on this page using dependency injection.
private readonly IInfoProvider<ContactInfo> contactInfoProvider;
private readonly IInfoProvider<ContactGroupInfo> contactGroupInfoProvider;
private readonly IInfoProvider<ContactGroupMemberInfo> contactGroupMemberInfoProvider;


public ContactGroupsServices(IInfoProvider<ContactInfo> contactInfoProvider,
                     IInfoProvider<ContactGroupInfo> contactGroupInfoProvider,
                     IInfoProvider<ContactGroupMemberInfo> contactGroupMemberInfoProvider)
{
    this.contactInfoProvider = contactInfoProvider;
    this.contactGroupInfoProvider = contactGroupInfoProvider;
    this.contactGroupMemberInfoProvider = contactGroupMemberInfoProvider;
}
> Back to list of examples

Contact groups

Create contact groups

C#
// Creates a new contact group object
ContactGroupInfo newGroup = new ContactGroupInfo()
{
    ContactGroupDisplayName = "New group",
    ContactGroupName = "NewGroup",
    ContactGroupEnabled = true,
    ContactGroupDynamicCondition = "{%Rule(\"(Contact.AgreedWithConsent(\"form\"))\"," +
    " \"<rules><r pos=\"0\" par=\"\" op=\"and\" /><r pos=\"0\" par=\"0\" op=\"and\" n=\"CMSContactHasAgreedWithConsent\" >" +
    "<p n=\"_perfectum\"><t>has</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p><p n=\"consent\">" +
    "<t>#select consent</t><v>form</v><r>0</r><d>select consent</d><vt>text</vt><tv>0</tv></p></r></rules>\") %}"
};

// Saves the contact group to the database
contactGroupInfoProvider.Set(newGroup);
> Back to list of examples

Update contact groups

C#
// Gets the contact group
ContactGroupInfo updateGroup = contactGroupInfoProvider.Get("NewGroup");

if (updateGroup != null)
{
    // Updates the contact group's properties
    updateGroup.ContactGroupDisplayName = updateGroup.ContactGroupDisplayName.ToLowerInvariant();

    // Saves the modified contact group to the database
    contactGroupInfoProvider.Set(updateGroup);
}
> Back to list of examples

Update multiple contact groups

C#
// Gets all contact groups whose name starts with 'New'
var groups = contactGroupInfoProvider.Get().WhereStartsWith("ContactGroupName", "New");

// Loops through individual contact groups
foreach (ContactGroupInfo group in groups)
{
    // Updates the contact group properties
    group.ContactGroupDisplayName = group.ContactGroupDisplayName.ToUpper();

    // Saves the modified contact group to the database
    contactGroupInfoProvider.Set(group);
}
> Back to list of examples

Delete contact groups

C#
// Gets the contact group
ContactGroupInfo deleteGroup = contactGroupInfoProvider.Get("NewGroup");

if (deleteGroup != null)
{
    // Deletes the contact group
    contactGroupInfoProvider.Delete(deleteGroup);
}
> Back to list of examples