OCAPI メタデータ 23.1

Open Commerce API は、Open Commerce API 自体に関するデータ (メタデータ) を提供します。API メタデータは、所有 API である Meta API にアクセスして取得できます。この API は Shop API や Data API と同じようにアクセスできますが、API バージョンとしてバージョン 1 が必要です。Meta API は次の情報を提供します:

Meta API にアクセスするには、すべてのリクエストにおいて、Authorization: Bearer OAuth トークン を送信します。これは Account Manager で取得できます。アクセストークンの作成に使用したクライアント ID で、OCAPI 設定に基づいてすべてのリソースへのアクセスが確認され、使用可能なリソースとドキュメントのみが表示されます。メタデータへのアクセスに使用されるコンテキストに応じて、結果が異なる場合があります。特定サイトのコンテキストでは、当該サイトの OCAPI 設定は、リクエスト元のクライアントのアクセス権を確認するために使用されます。この場合、アクセスが許可されているリソースのみが表示されます。グローバルコンテキストでメタデータにアクセスする場合も、同じことが当てはまります。この場合は、グローバル OCAPI 設定は、クライアントがアクセス可能なメタデータのみを取得するために使用されます。

Meta API レスポンスは、ページキャッシュで 24 時間キャッシュされます。つまり、このメタデータのキャッシュはページキャッシュのクリアで自動的にクリアされます。

API のリスト 

次の例は、使用可能な API のリストを示します:

1REQUEST:
2GET /dw/meta/v1/rest HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6
7RESPONSE:
8HTTP/1.1 200 OK
9Content-Type: application/json;charset=UTF-8
10Cache-Control: max-age=900,must-revalidate
11Content-Length: 741
12{
13    "apis": [
14    {
15        "link": "https://example.com/s/-/dw/meta/v1/rest/data",
16        "name": "data"
17    },
18    {
19        "link": "https://example.com/s/-/dw/meta/v1/rest/meta",
20        "name": "meta"
21    },
22    {
23        "link": "https://example.com/s/-/dw/meta/v1/rest/shop",
24        "name": "shop"
25    }]
26}

バージョンのリスト 

次の例は、使用可能な API バージョンのリストを示します:

1REQUEST:
2GET /dw/meta/v1/rest/data HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6
7RESPONSE:
8HTTP/1.1 200 OK
9Content-Type: application/json;charset=UTF-8
10Cache-Control: max-age=900,must-revalidate
11Content-Length: 741
12{
13    "versions": [
14    {
15        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v14_2",
16        "name": "14.2",
17        "status": "deprecated"
18    },
19    {
20        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v14_6",
21        "name": "14.6",
22        "status": "deprecated"
23    },
24    ...
25    {
26        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v23_1",
27        "name": "23.1",
28        "status": "current"
29    }
30    ]
31}

リソースの説明のリスト 

取得されたドキュメントは、Swagger のバージョン 2.0 とともに使用され、すべてのリソースパスと、その入力パラメーターおよび戻り値タイプの説明をリストします。次の例は、サポートされているリソース URI のリストを示します:

1REQUEST:
2GET /dw/meta/v1/rest/data/v23_1 HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6x-dw-pretty-print: true
7
8RESPONSE:
9HTTP/1.1 200 OK
10Content-Type: application/json;charset=UTF-8
11Cache-Control: max-age=900,must-revalidate
12Content-Length: 5981
13{
14    "info":
15    {
16        "version": "23.1",
17        "title": "Data API"
18    },
19    "swagger": "2.0",
20    "basePath": "https://example.com/s/-/dw/data/v23_1",
21    "paths":
22    {
23        "/customer_search":
24        {
25            "post":
26            {
27                "operationId": "customerSearchcustomer_search",
28                "responses":
29                {
30                    "default":
31                    {
32                        "schema":
33                        {
34                            "$ref": "#/definitions/customer_search_result"
35                        }
36                    }
37                },
38                "tags": [
39                    "customer_search"
40                ],
41                "parameters": [
42                {
43                    "in": "body",
44                    "required": true,
45                    "schema":
46                    {
47                        "$ref": "#/definitions/customer_search_request"
48                    },
49                    "name": "body"
50                }]
51            }
52        },
53        ...
54    },
55    "definitions":
56    {
57        ...,
58        "customer_search_result":
59        {
60            "properties":
61            {
62                "count":
63                {
64                    "format": "int32",
65                    "type": "integer"
66                },
67                "hits":
68                {
69                    "items":
70                    {
71                        "$ref": "customer_search_hit"
72                    },
73                    "type": "array"
74                },
75                ...
76            },
77            "id": "customer_search_result"
78        },
79        ...
80    }
81}

ドキュメントのリスト 

次の例は、特定バージョンの API の使用可能なドキュメントをすべて示します:

1REQUEST:
2GET /dw/meta/v1/rest/data/v23_1/documents HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6x-dw-pretty-print: true
7
8RESPONSE:
9HTTP/1.1 200 OK
10Content-Type: application/json;charset=UTF-8
11Cache-Control: max-age=900,must-revalidate
12Content-Length: 741
13{
14    "data": [
15    {
16        "id": "credentials",
17        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v23_1/documents/credentials"
18    },
19    {
20        "id": "customer",
21        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v23_1/documents/customer"
22    },
23    {
24        "id": "customer_address",
25        "link": "https://example.com/s/-/dw/meta/v1/rest/data/v23_1/documents/customer_address"
26    },
27    ...]
28}

ドキュメント情報の表示 

次の例は、リクエストされた特定バージョンの API ドキュメントのメタデータを示します:

1REQUEST:
2GET /dw/meta/v1/rest/data/v23_1/documents/customer_address_result HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6x-dw-pretty-print: true
7
8RESPONSE:
9HTTP/1.1 200 OK
10Content-Type: application/json;charset=UTF-8
11Cache-Control: max-age=900,must-revalidate
12Content-Length: 741
13{
14    "properties":
15    {
16        "count":
17        {
18            "format": "int32",
19            "type": "integer"
20        },
21        "data":
22        {
23            "items":
24            {
25                "$ref": "https://example.com/s/-/dw/meta/v1/rest/data/v23_1/documents/customer_address"
26            },
27            "type": "array"
28        },
29        "next":
30        {
31            "type": "string"
32        },
33        ...
34    }
35}

また、クエリパラメーター children=embedded を追加して、下位ドキュメントの定義を含めることも可能です:

1REQUEST:
2GET /dw/meta/v1/rest/data/v23_1/documents/customer_address_result?children=embedded HTTP/1.1
3Host: example.com
4Accept: application/json
5Authorization: Bearer <access_token>
6
7RESPONSE:
8HTTP/1.1 200 OK
9Content-Type: application/json;charset=UTF-8
10Cache-Control: max-age=900,must-revalidate
11Content-Length: 741
12{
13    "properties":
14    {
15        "count":
16        {
17            "format": "int32",
18            "type": "integer"
19        },
20        "data":
21        {
22            "items":
23            {
24                "customer_address":
25                {
26                    "required": [
27                        "address_id",
28                        "country_code",
29                        "last_name"
30                    ],
31                    "properties":
32                    {
33                        "address1":
34                        {
35                            "maxLength": 256,
36                            "type": "string"
37                        },
38                        ...
39                    }
40                }
41            },
42            "type": "array"
43        },
44        ...
45    },
46    "id": "customer_address_result"
47}