---
title: "体験のためのAPIリクエストを作成する"
slug: "compose-the-api-request-for-an-experience"
abstract: "トリガーされた体験のためのAPIリクエストの作成方法の詳細を提供します。"
---
# 体験のためのAPIリクエストを作成する

トリガーされた体験用の [ウェブフック](https://doc.sitecore.com/personalize/ja/users/sitecore-personalize/introduction-to-experiments-in-sitecore-personalize/introduction-to-triggered-experiments-in-sitecore-personalize/compose-a-webhook-for-a-triggered-experiment.html "Compose a webhook for a triggered experiment") を作成した後は、[決定モデルから返されるコンテンツを含める](https://doc.sitecore.com/personalize/ja/users/sitecore-personalize/introduction-to-experiments-in-sitecore-personalize/introduction-to-triggered-experiments-in-sitecore-personalize/compose-the-api-request-for-an-experiment/use-dynamic-decision-model-data-in-the-api-request-for-a-triggered-experiment.html "Use dynamic decision model data in the API request for a triggered experiment") ためのAPIリクエストを作成し、選択したウェブフック宛先に送信する必要があります。

APIリクエストはゲストデータモデルや体験応答からの動的なデータを含めることを可能にします。例えば、トリガーされた体験のバリアントにゲストの名前、所在地、ロイヤルティ番号などを含めるようにしたい場合もあります。 [リクエストはFreeMarker](https://try.freemarker.apache.org/)を使って設定します。

トリガーされた体験のためのAPIリクエストを作成するには:

1.  APIエディターの**APIリクエスト** タブで、ドロップダウンリストを使ってデータを送信したい外部宛先を選択します。
    
2.  必要に応じて、リクエストに追加ヘッダーを追加するには「 **ヘッダーを追加**」をクリックしてください。
    
    > !注ここで追加するヘッダーにはFreeMarkerの変数を含めることはできません。ヘッダーにFreeMarker変数が必要な場合は、[外部宛先へのリクエストを設定する](https://doc.sitecore.com/personalize/ja/users/sitecore-personalize/introduction-to-experiences/introduction-to-triggered-experiences-in-sitecore-personalize/connect-sitecore-personalize-to-an-external-destination.html "Connect Sitecore Personalize to an external destination")際に作成しなければなりません。
    
3.  接続にFreeMarker変数が含まれている場合は、「 **変数値を設定** 」をクリックして各変数の値を指定します。その後、「 **保存**」をクリックします。
    
    > !注文字列の値を二重引用符で囲む、例えば "test-value"。
    
4.  **API ボディ**タブをクリックして、APIリクエストのボディを合成してください。
    
    FreeMarkerの変数表記法 ${}を用いて変数を含めることができます。例えば、[ゲストデータモデル](https://doc.sitecore.com/personalize/ja/users/sitecore-personalize/introduction-to-experiments-in-sitecore-personalize/introduction-to-triggered-experiments-in-sitecore-personalize/compose-the-api-request-for-an-experiment/use-guest-data-in-the-api-request-for-a-triggered-experiment.html "Use guest data in the API request for a triggered experiment") や [意思決定モデルの応答](https://doc.sitecore.com/personalize/ja/users/sitecore-personalize/introduction-to-experiments-in-sitecore-personalize/introduction-to-triggered-experiments-in-sitecore-personalize/compose-the-api-request-for-an-experiment/use-dynamic-decision-model-data-in-the-api-request-for-a-triggered-experiment.html "Use dynamic decision model data in the API request for a triggered experiment")から動的データをコピー&ペーストすることができます。
    
    以下は、ゲストデータモデルの変数を用いた放棄されたカートメールのAPIリクエストボディの例です:
    
    {
     "from": "noreply@myretailsite.com",
     "to": "${guest.email}",
     "subject": "Don't forget your favorite pair of shoes",
     "body": "Hello, ${guest.firstName}. We noticed that you left a pair of shoes in your cart..."
    }
    
5.  **「保存**」をクリックします。
    
6.  APIエディターを閉じるには ![back.png](https://doc.sitecore.com/api/markdown-image/personalize/ja/users/sitecore-personalize/images/back.png) をクリックしてください。