1. その他の開発タスク

リスト マネージャー API

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

Sitecoreは、コンタクト リストをマーケティング定義として保存します。Content Manager (CM) インスタンスでは、List Manager APIを使用してプログラムで連絡先リストにアクセスできます。

メモ

Content Delivery (CD) インスタンスではList Manager APIを使用できません。これは、この場合、List Managerアプリケーションが無効になっているためです。

セグメントの追加、更新、および削除

この例では、List Manager APIを使用してセグメントを追加する方法を示します。

手記

セグメントルールの作成と変更は、リストマネージャーインターフェースを介してのみ実行できます。

var segmentRepository = ServiceLocator.ServiceProvider.GetService< SegmentRepository>();

var newSegment = new SegmentModel
      {
         Id = Guid.NewGuid().ToString("B"),
         Name = "New Segment",
         Description = "New Description",
         UseAsAnalyticsFilter = true
      };

segmentRepository.Add(newSegment);

この例では、セグメントを更新する方法を示します。

var segmentRepository = ServiceLocator.ServiceProvider.GetService< SegmentRepository>();

//Find existing segment by ID. ID must be vali
var segmentToUpdate =  segmentRepository.FindById("{00000000-0000-0000-0000-000000000000}");
segmentToUpdate.Description = "New Description";
segmentRepository.Update(segmentToUpdate);

この例では、セグメントを削除する方法を示します。

var segmentRepository = ServiceLocator.ServiceProvider.GetService<IFetchRepository<SegmentModel>>();

//Find existing segment by ID. ID must be valid.

var segmentToDelete =  segmentRepository.FindById("{00000000-0000-0000-0000-000000000000}");
segmentRepository.Delete(segmentToDelete);

セグメント化されたリストを追加、更新、および削除する

この例では、セグメント化されたリストを追加する方法を示します。

var segmentedListRepository = ServiceLocator.ServiceProvider.GetService< SegmentedListRepository>();

var newSegmentedList = new SegmentedListModel()
            {
                Id = Guid.NewGuid().ToString("B"),
                Name = "New Contact List",
                Description = "Description of the contact list",
                Owner = "Administrator"
            };

作成するリストにセグメントを追加するには、次のコード スニペットを使用します。

newSegmentedList .SegmentIds = new[] {“<Guid of the Segment>”};

新しいセグメント化されたリストを保存するには、次のコード スニペットを使用します。

segmentedListRepository.Add(newSegmentedList);

この例では、セグメント化されたリストを更新する方法を示します。

var segmentedListRepository = ServiceLocator.ServiceProvider.GetService< SegmentedListRepository>();

//Find existing list by ID. ID must be valid.

var listToUpdate =  segmentedListRepository.FindById("{00000000-0000-0000-0000-000000000000}");
listToUpdate.Description = "New Description";
segmentedListRepository.Update(listToUpdate);

この例では、セグメント化されたリストを削除する方法を示します。

var segmentedListRepository = ServiceLocator.ServiceProvider.GetService<IFetchRepository<SegmentedListModel>>();

//Find existing list by ID. ID must be valid.

var listToDelete =  segmentedListRepository.FindById("{00000000-0000-0000-0000-000000000000}");
segmentedListRepository.Delete(listToDelete);

連絡先リストを追加、更新、および削除する

この例では、連絡先リストを追加する方法を示します。

var contactListRepository = ServiceLocator.ServiceProvider.GetService<IFetchRepository< ContactListModel>>();
var newContactList = new ContactListModel()
       {
           Id = Guid.NewGuid().ToString("B"),
           Name = "New Contact List",
           Description = "Description of the contact list",
           Owner = "Administrator"
        };

作成するリストにインクルード リストを追加するには、次のコード スニペットを使用します。

newContactList.Subscriptions.Add(new SubscriptionViewModel
            {
               Id = Guid.NewGuid(),
               ListId = <Guid of the List>, 
               Name= "Name of the included list"
            });

新しい連絡先リストを保存するには、次のコード スニペットを使用します。

contactListRepository.Add(newContactList);

この例では、連絡先リストを更新する方法を示します。

var contactListRepository = ServiceLocator.ServiceProvider.GetService<IFetchRepository< ContactListModel>>();

//Find existing list by ID. ID must be valid.
var listToUpdate =  contactListRepository.FindById("{00000000-0000-0000-0000-000000000000}");
listToUpdate.Description = "New Description";
contactListRepository.Update(listToUpdate);

この例では、連絡先リストを削除する方法を示します。

var contactListRepository = ServiceLocator.ServiceProvider.GetService<IFetchRepository< ContactListModel>>();

//Find existing list by ID. ID must be valid.

var listToDelete =  contactListRepository.FindById("{00000000-0000-0000-0000-000000000000}");
contactListRepository.Delete(listToDelete);

連絡先の追加と削除

次の例は、連絡先リストに1つの連絡先を追加する方法を示しています。

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

次の例は、連絡先リストに複数の連絡先を追加する方法を示しています。

var contacts = new List<Contact>(); // List of contacts
var subscriptionService = ServiceLocator.ServiceProvider.GetService<ISubscriptionService>();
subscriptionService.Subscribe(contactListId, contacts);

連絡先の関連付けを削除し、対応するメソッドを ISubscriptionServiceから呼び出すには、次のようにします。

var subscriptionService = ServiceLocator.ServiceProvider.GetService<ISubscriptionService>();
subscriptionService.Unsubscribe(contactListId, contactId);
subscriptionService.Unsubscribe(contactListId, contacts);

リストに関連付けられた連絡先を取得する

次の例は、連絡先リストから連絡先を取得する方法を示しています。

int batchSize = 200; // Size of the batch
string[] facets =
{
    CollectionModel.FacetKeys.PersonalInformation,    
    CollectionModel.FacetKeys.ListSubscriptions
}; // Contact facets to retrieve
var contactListProvider = ServiceLocator.ServiceProvider.GetService<IContactListProvider>();
var contactProvider = ServiceLocator.ServiceProvider.GetService<IContactProvider>();
var contactList = contactListProvider.Get(contactListId, cultureInfo);
var contactBatchEnumerator = contactProvider.GetContactBatchEnumerator(
    contactList,     
    batchSize,
     facets);
while (contactBatchEnumerator.MoveNext())
{    
var contacts = contactBatchEnumerator.Current;
    // write your logic here
    contacts.ToList();
}

この例では、接触を反復処理する最も効率的で最速の方法としてバッチ列挙子を使用します。詳細については、xConnectのドキュメントを参照してください。

この記事を改善するための提案がある場合は、 お知らせください!