GenericSearch API を使用した Commerce エンティティの検索
Postman で GenericSearch API サンプル コマンドを使用して Commerce エンティティを検索する方法。
Sitecore Experience Commerce SDK には、SearchApiSamples Postman のコレクションの一部として GenericSearch
API コマンドが含まれています。サンプル要求を使用して Commerce Engine でインデックス付き Commerce エンティティを検索できます。検索プラグインは、GenericSearch API エンドポイントを汎用検索フレームワークの一部として定義します。検索プロバイダーに依存しない構文を使用して GenericSearch クエリを作成します。カタログ アイテム、プロモーション、注文、プライス カード、または顧客を検索できます。
以下の手順は、Postman アプリケーションのインストール、Sitecore Commerce Engine SDK からのサンプル コレクションのインポート、環境の設定、Commerce Engine API へのアクセス用のベアラー トークンの取得が完了していることを前提とします。詳細については、こちらを参照してください。
GenericSearch サンプルを使用して、カタログ アイテムなどの Commerce エンティティを検索するには:
Postman の [Collections] ペインで、SearchAPISamples コレクションを展開します。
API フォルダーを開き、[ POST GenericSearch] 要求 (
{{ServiceHost}}/{{ShopsApi}}/GenericSearch()
) をクリックします。[Body] タブをクリックし、クエリ パラメーターを更新して検索クエリを作成します。次の例は、「InstaClix Instant Film Camera」という名前に一致する販売可能アイテムのサンプル Habitat_Master カタログを検索するために作成されたクエリを示しています。
{ "searchScope": "<hostname>-CatalogItemsScope", "searchQuery": null, "filterQuery": { "FilterNode": { "@odata.type": "#Sitecore.Commerce.Plugin.Search.EqualsFilterNode", "FieldName": { "@odata.type": "#Sitecore.Commerce.Plugin.Search.FieldNameFilterNode", "Name": "name" }, "FieldValue": { "@odata.type": "#Sitecore.Commerce.Plugin.Search.FieldValueFilterNode", "Value": "Habitat_Master", "ValueType": "1" } } }, "searchOptions": { "Skip": "0", "Top": "3", "ResultsOrderFields": [], "FieldsToRetrieve": [] } }
[Send] をクリックします。返される検索結果の例を次に示します。
{ "@odata.context": "https://cqa-dem-01-dk1:5000/api/$metadata#Collection(Sitecore.Commerce.Plugin.Search.SearchResult)", "value": [ { "Fields": [ { "Key": "sitecoreid", "Value": "46455327-796c-8125-b838-f6d7f678303d" }, { "Key": "entityuniqueid", "Value": "6d737cc2-333b-ae32-73f0-cc3d67631409" }, { "Key": "entityid", "Value": "Entity-SellableItem-7042066" }, { "Key": "entityversion", "Value": "1" }, { "Key": "productid", "Value": "7042066" }, { "Key": "displayname", "Value": "InstaClix Instant Film Camera" }, { "Key": "name", "Value": "InstaClix Instant Film Cmera" }, { "Key": "datecreated", "Value": "5/16/2019 2:09:35 PM +00:00" }, { "Key": "dateupdated", "Value": "2/29/2020 10:57:28 AM +00:00" }, { "Key": "artifactstoreid", "Value": "78a1ea61-1f37-42a7-ac89-9a3f46d60ca5" }, { "Key": "parentcataloglist", "Value": "[\"59ddadc1-9b88-727e-9e14-3f6cf321ae0f\"]" }, { "Key": "variantid", "Value": "57042066|57042067|57042068| 57042069|57042070" }, { "Key": "variantdisplayname", "Value": "InstaClix Instant Film Camera (Blue)|InstaClix Instant Film Camera (Red)| InstaClix Instant Film Camera (Green)|InstaClix Instant Film Camera (Teal)|InstaClix Instant Film Camera (Pink)" }, { "Key": "inventorysetids", "Value": "Entity-InventorySet-Habitat_Inventory" }, { "Key": "_version_", "Value": "1659868448064274437" } ] } ] }
注記
汎用検索フレームワークは、クエリの作成に使用できる検索ノードとフィルター ノード、条件、演算子を定義します。