---
title: "REST APIを用いた統合"
slug: "integrating-using-rest-apis"
abstract: "Sitecore Search APIと連携する方法を公開し、基本的な流れを提供するREST APIを一覧にしています。"
---
# REST APIを用いた統合

ウェブサイトやアプリケーションをSitecore Searchと統合する方法の一つに、REST APIを使うことがあります。

> !注もし組織に[JSS Next.js](https://doc.sitecore.com/sai/en/developers/jss/22/jss-sai/javascript-services-sdk--jss--for-next-js.html)やJSS AngularアプリケーションがSitecore XM Cloudに接続されている場合は、[Sitecore Cloud SDK](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/sitecore-cloud-sdk-for-javascript.html)を使ってXM CloudサイトにSitecore Search関連機能を実装してください。また、[クラウドSDKとSitecore Search REST APIの比較](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/en/cloud-sdk-comparison-charts.html)も参照してください。

Searchは統合のために以下のAPIを提供しています:

-   **Search and Recommendation** - [Search and Recommendation API](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-the-search-and-recommendation-api-to-create-search-experiences.html "Using the Search and Recommendation API to create search experiences")を使って顧客の検索体験を作成できます。検索結果の取得、フィルタリング、ソート、パーソナライズ、コンテンツの提案などが可能です。
    
    Search and Recommendation APIを使う際は、詳細なデータモデルやオブジェクト・キーの説明については[APIリファレン](https://doc.sitecore.com/search/en/developers/search-and-recommentation-api/index.html) スを参照してください。
    
-   **Events** - [イベントAPI](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-the-events-api-to-track-events.html "Using the Events API to track events")を使って、ウェブサイトやモバイルアプリの訪問者の行動やその他のイベントをキャプチャし報告します。イベントはSearchのAIコアで重要なシグナルの一つです。
    
    Events APIを扱う際は、すべてのオブジェクトやキーの詳細なデータモデルや記述については[APIリファレン](https://doc.sitecore.com/search/en/developers/events-api/index.html) スを参照してください。
    
-   **Authentication** - [認証API](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/api-authentication-and-authorization.html "API authentication and authorization")を使って、Searchへのリクエストを認証するための鍵やトークンを取得します。これはサブドメインがない場合のみ適用されます。
    

## 典型的なAPI統合フロー

以下はAPIを使ってSearchと統合する際の典型的なワークフローです:

1.  サブドメインがない場合は、[APIキーかアクセストークンを取得し](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/api-authentication-and-authorization.html "API authentication and authorization")てください。サブドメインがある場合は認証は不要です。
    
2.  各訪問者ごとに匿名 [の一意識別子](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-a-uuid-to-track-site-visitors.html "Using a UUID to track site visitors") を作成する方法を計画しましょう。
    
    これは必須ではありませんが、複数のセッションにまたがるリクエストを訪問者に紐付けるために、各訪問者に対して匿名の識別子を作成・送信することを強くお勧めします。これにより、パーソナライズされた検索結果を提供し、分析を生成できます。
    
3.  管理者から以下の情報を収集してください:
    
    -   望ましい検索体験を作るために必要なウィジェットやページ。例えば、ビジネス要件として、会社のホームページには全ページ検索を表示するが、各縦欄ごとにページにはpreview searchのみを表示することがあるかもしれません。
        
    -   各検索体験ごとにどのコンテンツを提供すべきか。ドメインのすべての [インデックスコンテンツ](https://doc.sitecore.com/search/en/users/search-user-guide/index-items.html) がすべての検索体験で利用可能である必要はありません。例えば、会社のホームページの全ページ検索では、利用可能なすべてのコンテンツを検索する必要があるかもしれません。しかし、ある縦業界のページのpreview searchは、その分野に関連するコンテンツのみを検索する必要があるかもしれません。
        
    -   facetsやソートなどの機能が各検索体験に必要なものや、それらの設定方法についても教えてください。
        
        > !注管理者はSearchで多くの機能を設定しますが、実行時にいくつかの設定を渡す必要があるかもしれません。
        
4.  [Search and Recommendation APIに対してテストリクエストを作成し](https://doc.sitecore.com/search/ja/developers/search-developer-guide/the-sitecore-search-interface/the-api-explorer-tab/test-a-search-request-using-the-api-explorer.html "Test a search request using the API Explorer")ましょう。この段階で、応答を研究し、どの部分を使って検索体験を作成するかも確認してください。
    
5.  アプリケーション内で、Search and Recommendation APIへのリクエストを作成するコードを追加してください。また、検索体験を作成するために必要なレスポンス部分を取得するコードも追加してください。
    
    [ユースケース](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-the-search-and-recommendation-api-to-create-search-experiences.html "Using the Search and Recommendation API to create search experiences")を研究し、[API参照](https://doc.sitecore.com/search/en/developers/search-and-recommentation-api/index.html)のデータモデルを見てリクエストを作成しましょう。
    
6.  Events APIにリクエストを送信するコードを追加します。訪問者の行動に応じて多くのイベントが起こり得ます。
    
    [ユースケース](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/using-the-events-api-to-track-events.html "Using the Events API to track events")を研究し、[API参照](https://doc.sitecore.com/search/en/developers/events-api/index.html)のデータモデルを見てリクエストを作成しましょう。
    
7.  ウェブサイトやアプリをDeployしましょう。
    
    ウェブサイトやアプリが展開された後は [、イベントを監視](https://doc.sitecore.com/search/ja/developers/search-developer-guide/the-sitecore-search-interface/using-the-event-monitor.html "Using the Event Monitor") し、Events APIに送るリクエストの調整を行うことができます。
    
    > !注アプリケーションで他の検索機能も無効にすることをお勧めします。これは多くのクローラーがコンテンツをクロールするストレスを減らすためです。
    

訪問者が検索ページに到着し、検索し、ファセットを選択し、フィルタリングし、その後content itemをクリックするというユースケースに対応するための [サンプルリクエストを含むウォークスルー](https://doc.sitecore.com/search/ja/developers/search-developer-guide/integrating-using-rest-apis/walkthrough--using-apis-to-create-a-search-experience-and-send-events.html "Walkthrough: Using APIs to create a search experience and send events") を作成しました。

> !重要ソースを指定するリクエストは以下のステータスコードを返します:
> 
> ステータスコードが戻りました
> 
> 概要
> 
> 200
> 
> ソースが初期化されたり、インデックス実行が成功した場合に。ソースがアイテムをインデックスする必要はない。
> 
> 500
> 
> ソースが初期化されていない場合。