---
title: "ODataアイテムサービス"
slug: "the-odata-item-service"
abstract: "ODataアイテムサービスの概要"
---
# ODataアイテムサービス

Sitecoreアイテムへの読み取り専用アクセスにはODataアイテムサービスを使用します。このサービスはAPIキーを使ってリクエストを認証します。サービスは /sitecore/api/ssc/aggregate/content/Itemsエンドポイントを公開します。データはOData(JSON)形式で返します。

このトピックでは以下の内容を説明します:

-   [リクエストセキュリティコンテキスト](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/the-odata-item-service.html#UUID-4666a88f-48f6-6fa7-059a-30e1dbbc2d14_id__The_request_security "The request security context")
-   [APIキーの使用](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/the-odata-item-service.html#UUID-4666a88f-48f6-6fa7-059a-30e1dbbc2d14_N1525856654948)
-   [アイテムの回収](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/the-odata-item-service.html#UUID-4666a88f-48f6-6fa7-059a-30e1dbbc2d14_N1525856664659)
-   [フィールドフォーマット](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-manager/the-odata-item-service.html#UUID-4666a88f-48f6-6fa7-059a-30e1dbbc2d14_N1530091877605 "Field format")

## リクエストセキュリティコンテキスト

Sitecoreは、現在のSitecoreユーザーのセキュリティ文脈でODataアイテムサービスへのリクエストを実行します。

ODataアイテムサービスには匿名でアクセスできます。Sitecore Sitecore.Services.AnonymousUser設定で定義されたユーザーのセキュリティコンテキスト内で匿名リクエストを実行します。このようなリクエストはユーザーなりすましを用い、デフォルトでsitecore\\ServicesAPIユーザーとして実行されます。

## APIキーの使用

すべてのリクエストでAPIキーをOData Item Serviceに渡さなければなりません。GETリクエストではAPIを渡します。例えば:

sitecore/api/ssc/aggregate/content/Items('{<item id>}')?sc\_apikey=<api key>

OData Item API Keyテンプレートは、OData Item Serviceで使用される2つのフィールドを導入します:

**フィールド**

**概要**

**例**

データベース

取得するデータベース名を指定します。このフィールドは必須です。

web

Search Filter

ODataフィルター形式で検索オプションを指定します。ODataアイテムサービスはandオペレーターを用いて$filterパラメータの値に加えます。このフィールドは任意です。

TemplateName eq 'Sample Item'  
  
標準値: IsLatestVersion eq true (アイテムの最新バージョンのみを返す)

フィールドは大文字を区別します。

## アイテムの回収

以下の小節の表は、ODataアイテムサービスに対して一般的なGETリクエストをどのように実行するかを示しています。簡潔にするために、APIキーは構文には表示されていません。

### キーでアイテムを取得する方法

これらのリクエストは1つ以上のアイテムを取得します。

**要請の目的**

**構文論**

アイテムIDで識別されるアイテムを取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')

パスで識別されたアイテムを取得する

/sitecore/api/ssc/aggregate/content/Items('/sitecore/content/Home')

カスタムフィールドを含むアイテムの取得

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?$expand=Fields

カスタムフィールド値(名前/値フィールド形式)を取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?$expand=FieldValues

カスタムフィールドと標準フィールドを含むアイテムを取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?$expand=Fields, StandardFields

カスタムおよび標準フィールド値(名前/値フィールド形式)を取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?$expand=FieldValues, StandardFieldValues

アイテムのすべての子を取得

/sitecore/api/ssc/aggregate/content/Items('/sitecore/content')/Children

アイテムの親を取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')/Parent

特定の言語バージョンのアイテムを取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?language=ja-JP

アイテムの特定のバージョンを取得する

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}' )?version=2

プロパティプロジェクション付きのアイテム取得(指定されたアイテムプロパティのみ提供)

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}' )?$select=Id,Name,TemplateName

フィールド投影付きのアイテム取得(指定されたフィールドプロパティのみを提供)

/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}' )?expand=Fields($select=Name,Value)  
  
Sitecore 9、Update 2以降では、代わりに以下を使います:  
  
/sitecore/api/ssc/aggregate/content/Items('{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}')?$expand=FieldValues($select=Title,Text

### アイテム検索

これらのリクエストはSitecoreのコンテンツ検索を使ってアイテムを検索し、ODataアイテムサービスの検索は一般的なコンテンツ検索と同じ機能を持っています。

**要請の目的**

**構文論**

アイテムプロパティによるSearch

/sitecore/api/ssc/aggregate/content/Items?$filter=Name eq 'Home'

複数のアイテムプロパティによるSearch

/sitecore/api/ssc/aggregate/content/Items?$filter=Name eq 'Home' and TemplateName eq 'Sample Item'

Search フィールド値によるもの(例ではフィールド Title が 'Welcome'と等しくない項目を取得します)

/sitecore/api/ssc/aggregate/content/Items?$filter=FieldValues/Title ne 'Welcome'  
  
フィルタリングするプロパティを展開する必要はありません。例えば、FieldValuespropertyでフィルタリングしつつ、Fieldsを展開できます:  
  
/sitecore/api/ssc/aggregate/content/Items?$filter=FieldValues/Title ne 'Welcome'&amp;$expand=Fields

複数のフィールド値によるSearch

/sitecore/api/ssc/aggregate/content/Items?$filter=FieldValues/Title eq 'My Title' and FieldValues/Text eq 'My text'

日付と時間でSearch

/sitecore/api/ssc/aggregate/content/Items?$filter=TemplateName eq 'Sample Item' and Updated ge 2017-03-22T10:42:00Z

以下のODataオペレーターを利用できます:

オペレーター

概要

eq

対等

ne

等しくはない

gt

より大きい

ge

大または等分

lt

以下

le

それ以下または等しい

and

論理的および

or

論理的または

not

論理否定

以下のOData文字列関数を使用できます:

-   contains
-   startswith
-   endswith

### 検索結果のソート

検索結果をソート $orderbyするオプションで検索結果をソートできます。ソーマを区切りにして複数のプロパティを指定することもできます。デフォルトのソート順は昇順です。プロパティ名の後に「 desc 」キーワードを追加することでソート順を変えられます。

> !注ODataアイテムサービスは、ContentSearchコンポーネントが提供するソート機能を利用しています。

以下の例はソートアイテムを示しています:

**目的**

**構文論**

性質による順序

/sitecore/api/ssc/aggregate/content/Items?$orderby=Name

性質による降順の順序

/sitecore/api/ssc/aggregate/content/Items?$orderby=Name desc

複数の性質による順序

/sitecore/api/ssc/aggregate/content/Items?$orderby=Name, Created

場の値による順序

/sitecore/api/ssc/aggregate/content/Items?$orderby=FieldValues/Color

### ページ検索結果

検索結果の項目数を $skipと $topで制限します。 $skipオプションを使って、結果から指定されたアイテム数をスキップします。 $topオプションを使って結果に含まれるアイテム数を制限します。

$skipと$topの組み合わせを使ってページ付きコレクションを取得できます。

以下の例は、結果に対してページングを行う方法を示しています:

**目的**

**構文論**

トップ3のアイテムを入手しましょう

/sitecore/api/ssc/aggregate/content/Items?$top=3

最初のアイテムは飛ばして、他のアイテムを手に入れましょう

/sitecore/api/ssc/aggregate/content/Items?$skip=1

3つのアイテムを飛ばして、3つのアイテムを手に入れる

/sitecore/api/ssc/aggregate/content/Items?$skip=3&$top=3

## フィールドフォーマット

OData項目サービスは、2つの形式でフィールドを提供します:

-   フィールドをオブジェクトとして(Fields およびStandardFields プロパティ)
-   フィールドを名前/値ペアとして(FieldValues とStandardFieldValues プロパティ)

フィールド名のすべてのスペースはアンダースコア(「\_」)に置き換えられます。

### フィールドとスタンダードフィールド

OData Itemサービスは、FieldsおよびStandardFieldsプロパティの値をフィールドオブジェクトの集合として提供します。

"Fields": 
 {
 "Id": "5ab98be3-5e38-4cbf-95cf-0cb8d1929247",
 "Name": "Text",
 "Value": "Welcome to Sitecore",
 "Type": "Single-Line Text",
 ...
 },
 {
 "Id": "b293759d-9a2a-40d2-bb34-46e03952d3e9",
 "Name": "Number",
 "Value": "53",
 "Type": "Integer",
 ...
 },
 {
 "Id": "0b4ffcc9-153c-4de7-8563-2049cf1c933b",
 "Name": "Image",
 "Value": "<image mediaid=\\"{04DAD0FD-DB66-4070-881F-17264CA257E1}\\" alt=\\"This is alternate text\\" height=\\"\\" width=\\"\\" hspace=\\"1\\" vspace=\\"2\\" class=\\"ImageClass\\" />",
 "Type": "Image",
 ...
 "Url": "/-/media/Default-Website/cover.ashx",
 "Alt": "This is alternate text",
 "Width": "1600",
 "Height": "550",
 "Vspace": "2",
 "Hspace": "1",
 "Class": "ImageClass",
 "MediaItemId": "04dad0fd-db66-4070-881f-17264ca257e1"
 }

### 画像フィールド

OData Itemサービスは、画像フィールド(URL、Altなど)に追加のプロパティを提供します。

### フィールド値と標準フィールド値

Odata項目サービスは、FieldValuesおよびStandardFieldValuesプロパティの値を単純なオブジェクトとして提供します。このオブジェクトのプロパティはフィールド(フィールド名と値)を表しています:

"FieldValues": {
 "$count": 3,

 "Text": "Welcome to Sitecore",

 "Number": "53",

 "Image": "<image mediaid=\\"{04DAD0FD-DB66-4070-881F-17264CA257E1}\\" alt=\\"This is alternate text\\" height=\\"\\" width=\\"\\" hspace=\\"1\\" vspace=\\"2\\" class=\\"ImageClass\\" />",

 "Image\_\_Url": "/-/media/Default-Website/cover.ashx",
 "Image\_\_Alt": "This is alternate text",
}

$countは、アイテムが持つフィールドの数を示すサービスプロパティです。

### 画像フィールド

OData Itemサービスは、画像フィールド(URL、Altなど)に追加のプロパティを提供します。追加プロパティの名前には以下のフォーマットが使われます:<field-name>\_\_<extra-name>。