Programmatically create contact list

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












I know how to programmatically add contacts to a contact list, either through the contact itself, or through the List Manager API:



xContact.SetListSubscriptionsFacet(xConnectClient, listId);


Source: https://www.brimit.com/blog/sitecore-9-list-manager-changes



var subscriptionService = serviceLocator.ServiceProvider.GetService<ISubscriptionService>();
subscriptionService.Subscribe(contactListId, contactId);


Source: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/the_list_manager_api



But none of these services have anything on how to programmatically create a list. I can probably do it a dirty way by manually adding an item to /sitecore/system/Marketing Control Panel/Contact Lists (based on Contact List template), but if Sitecore needs to do some indexing or other things when creating lists, this will of course not be enough.



So how can I programmatically create a contact list?



Sitecore 9.0.2 (rev. 180604)










share|improve this question

























    up vote
    1
    down vote

    favorite
    1












    I know how to programmatically add contacts to a contact list, either through the contact itself, or through the List Manager API:



    xContact.SetListSubscriptionsFacet(xConnectClient, listId);


    Source: https://www.brimit.com/blog/sitecore-9-list-manager-changes



    var subscriptionService = serviceLocator.ServiceProvider.GetService<ISubscriptionService>();
    subscriptionService.Subscribe(contactListId, contactId);


    Source: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/the_list_manager_api



    But none of these services have anything on how to programmatically create a list. I can probably do it a dirty way by manually adding an item to /sitecore/system/Marketing Control Panel/Contact Lists (based on Contact List template), but if Sitecore needs to do some indexing or other things when creating lists, this will of course not be enough.



    So how can I programmatically create a contact list?



    Sitecore 9.0.2 (rev. 180604)










    share|improve this question























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I know how to programmatically add contacts to a contact list, either through the contact itself, or through the List Manager API:



      xContact.SetListSubscriptionsFacet(xConnectClient, listId);


      Source: https://www.brimit.com/blog/sitecore-9-list-manager-changes



      var subscriptionService = serviceLocator.ServiceProvider.GetService<ISubscriptionService>();
      subscriptionService.Subscribe(contactListId, contactId);


      Source: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/the_list_manager_api



      But none of these services have anything on how to programmatically create a list. I can probably do it a dirty way by manually adding an item to /sitecore/system/Marketing Control Panel/Contact Lists (based on Contact List template), but if Sitecore needs to do some indexing or other things when creating lists, this will of course not be enough.



      So how can I programmatically create a contact list?



      Sitecore 9.0.2 (rev. 180604)










      share|improve this question













      I know how to programmatically add contacts to a contact list, either through the contact itself, or through the List Manager API:



      xContact.SetListSubscriptionsFacet(xConnectClient, listId);


      Source: https://www.brimit.com/blog/sitecore-9-list-manager-changes



      var subscriptionService = serviceLocator.ServiceProvider.GetService<ISubscriptionService>();
      subscriptionService.Subscribe(contactListId, contactId);


      Source: https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/the_list_manager_api



      But none of these services have anything on how to programmatically create a list. I can probably do it a dirty way by manually adding an item to /sitecore/system/Marketing Control Panel/Contact Lists (based on Contact List template), but if Sitecore needs to do some indexing or other things when creating lists, this will of course not be enough.



      So how can I programmatically create a contact list?



      Sitecore 9.0.2 (rev. 180604)







      list-manager






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 59 mins ago









      GTHvidsten

      1337




      1337




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          For Sitecore 9.x, you need to go through the IDefinitionManager<IContactListDefinition> e.g.:



          var definitionManager = ServiceLocator.ServiceProvider.GetService<IDefinitionManager<IContactListDefinition>>();
          definitionManager.SaveAsync(new ContactListDefinition(Guid.NewGuid(), "alias", culture, "name", DateTime.UtcNow, createdBy))


          From



          • Sitecore.Marketing.dll





          share|improve this answer



























            up vote
            1
            down vote













            Here is the code which allows to create a contact list programatically in Sitecore:



            private Guid CreateContactList()

            ContactListModel entity = new ContactListModel();
            Guid guid = Guid.NewGuid();
            entity.Id = guid.ToString();
            entity.Type = ListType.ContactList.ToString();
            entity.Name = "My new contact list";

            IRepository<ContactListModel> contactListRepository = (IRepository<ContactListModel>) ServiceLocator.ServiceProvider.GetService(typeof(IRepository<ContactListModel>));
            contactListRepository.Add(entity);
            return guid;



            Remember to add references to:



            • Sitecore.ListManagement.Services.dll

            • Sitecore.Marketing.dll

            • Sitecore.Services.Core.dll





            share|improve this answer




















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "664"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14753%2fprogrammatically-create-contact-list%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              For Sitecore 9.x, you need to go through the IDefinitionManager<IContactListDefinition> e.g.:



              var definitionManager = ServiceLocator.ServiceProvider.GetService<IDefinitionManager<IContactListDefinition>>();
              definitionManager.SaveAsync(new ContactListDefinition(Guid.NewGuid(), "alias", culture, "name", DateTime.UtcNow, createdBy))


              From



              • Sitecore.Marketing.dll





              share|improve this answer
























                up vote
                2
                down vote













                For Sitecore 9.x, you need to go through the IDefinitionManager<IContactListDefinition> e.g.:



                var definitionManager = ServiceLocator.ServiceProvider.GetService<IDefinitionManager<IContactListDefinition>>();
                definitionManager.SaveAsync(new ContactListDefinition(Guid.NewGuid(), "alias", culture, "name", DateTime.UtcNow, createdBy))


                From



                • Sitecore.Marketing.dll





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  For Sitecore 9.x, you need to go through the IDefinitionManager<IContactListDefinition> e.g.:



                  var definitionManager = ServiceLocator.ServiceProvider.GetService<IDefinitionManager<IContactListDefinition>>();
                  definitionManager.SaveAsync(new ContactListDefinition(Guid.NewGuid(), "alias", culture, "name", DateTime.UtcNow, createdBy))


                  From



                  • Sitecore.Marketing.dll





                  share|improve this answer












                  For Sitecore 9.x, you need to go through the IDefinitionManager<IContactListDefinition> e.g.:



                  var definitionManager = ServiceLocator.ServiceProvider.GetService<IDefinitionManager<IContactListDefinition>>();
                  definitionManager.SaveAsync(new ContactListDefinition(Guid.NewGuid(), "alias", culture, "name", DateTime.UtcNow, createdBy))


                  From



                  • Sitecore.Marketing.dll






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 17 mins ago









                  Jacob Nielsen

                  2,025526




                  2,025526




















                      up vote
                      1
                      down vote













                      Here is the code which allows to create a contact list programatically in Sitecore:



                      private Guid CreateContactList()

                      ContactListModel entity = new ContactListModel();
                      Guid guid = Guid.NewGuid();
                      entity.Id = guid.ToString();
                      entity.Type = ListType.ContactList.ToString();
                      entity.Name = "My new contact list";

                      IRepository<ContactListModel> contactListRepository = (IRepository<ContactListModel>) ServiceLocator.ServiceProvider.GetService(typeof(IRepository<ContactListModel>));
                      contactListRepository.Add(entity);
                      return guid;



                      Remember to add references to:



                      • Sitecore.ListManagement.Services.dll

                      • Sitecore.Marketing.dll

                      • Sitecore.Services.Core.dll





                      share|improve this answer
























                        up vote
                        1
                        down vote













                        Here is the code which allows to create a contact list programatically in Sitecore:



                        private Guid CreateContactList()

                        ContactListModel entity = new ContactListModel();
                        Guid guid = Guid.NewGuid();
                        entity.Id = guid.ToString();
                        entity.Type = ListType.ContactList.ToString();
                        entity.Name = "My new contact list";

                        IRepository<ContactListModel> contactListRepository = (IRepository<ContactListModel>) ServiceLocator.ServiceProvider.GetService(typeof(IRepository<ContactListModel>));
                        contactListRepository.Add(entity);
                        return guid;



                        Remember to add references to:



                        • Sitecore.ListManagement.Services.dll

                        • Sitecore.Marketing.dll

                        • Sitecore.Services.Core.dll





                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Here is the code which allows to create a contact list programatically in Sitecore:



                          private Guid CreateContactList()

                          ContactListModel entity = new ContactListModel();
                          Guid guid = Guid.NewGuid();
                          entity.Id = guid.ToString();
                          entity.Type = ListType.ContactList.ToString();
                          entity.Name = "My new contact list";

                          IRepository<ContactListModel> contactListRepository = (IRepository<ContactListModel>) ServiceLocator.ServiceProvider.GetService(typeof(IRepository<ContactListModel>));
                          contactListRepository.Add(entity);
                          return guid;



                          Remember to add references to:



                          • Sitecore.ListManagement.Services.dll

                          • Sitecore.Marketing.dll

                          • Sitecore.Services.Core.dll





                          share|improve this answer












                          Here is the code which allows to create a contact list programatically in Sitecore:



                          private Guid CreateContactList()

                          ContactListModel entity = new ContactListModel();
                          Guid guid = Guid.NewGuid();
                          entity.Id = guid.ToString();
                          entity.Type = ListType.ContactList.ToString();
                          entity.Name = "My new contact list";

                          IRepository<ContactListModel> contactListRepository = (IRepository<ContactListModel>) ServiceLocator.ServiceProvider.GetService(typeof(IRepository<ContactListModel>));
                          contactListRepository.Add(entity);
                          return guid;



                          Remember to add references to:



                          • Sitecore.ListManagement.Services.dll

                          • Sitecore.Marketing.dll

                          • Sitecore.Services.Core.dll






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 25 mins ago









                          Marek Musielak

                          8,38311033




                          8,38311033



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14753%2fprogrammatically-create-contact-list%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery