CSV テンプレートからスキーマ変換API エンドポイント

Schema Registry APIの/rpc/csv2schema エンドポイントを使用すると、CSV ファイルをテンプレートとして使用して、Experience Data Model (XDM) スキーマを自動的に作成できます。 このエンドポイントを使用することで、スキーマフィールドを一括読み込みするテンプレートを作成し、手作業のAPI作業やUI作業を削減できます。

はじめに

/rpc/csv2schema エンドポイントはSchema Registry APIの一部です。 続行する前に、入門ガイド ​で、関連ドキュメントへのリンク、このドキュメントのサンプル API呼び出しを読むためのガイド、Adobe Experience Platform APIを正常に呼び出すために必要なヘッダーに関する重要な情報を確認してください。

/rpc/csv2schema エンドポイントは、Schema Registryでサポートされているリモート プロシージャ コール (RPC)の一部です。 Schema Registry APIの他のエンドポイントとは異なり、RPC エンドポイントはAcceptContent-Typeなどの追加ヘッダーを必要とせず、CONTAINER_IDを使用しません。 代わりに、以下のAPI呼び出しで示すように、/rpc名前空間を使用する必要があります。

CSV ファイルの要件

このエンドポイントを利用するには、まず、適切な列ヘッダーと対応する値を含むCSV ファイルを作成する必要があります。 一部の列は必須ですが、残りは任意です。 以下の表では、これらの列とスキーマ構築での役割について説明します。

CSV ヘッダーの位置
CSV ヘッダー名
必須/オプション
説明
1
isIgnored
オプション
含まれ、trueに設定されている場合、フィールドはAPI アップロードの準備ができていないため、無視する必要があることを示します。
2
isCustom
必須
フィールドがカスタムフィールドであるかどうかを示します。
3
fieldGroupId
オプション
カスタムフィールドを関連付けるフィールドグループのID。
4
fieldGroupName
(説明を参照)
このフィールドを関連付けるフィールドグループの名前。

既存の標準フィールドを拡張しないカスタムフィールドのオプション。 空白のままにすると、システムは名前を自動的に割り当てます。

標準フィールドまたは標準フィールドグループを拡張するカスタムフィールドに必須です。これは、fieldGroupIdを照会するために使用されます。
5
fieldPath
必須
フィールドの完全なXED ドット表記パス。 標準フィールドグループのすべてのフィールド(fieldGroupNameに示すように)を含めるには、値をALLに設定します。
6
displayName
オプション
フィールドのタイトルまたはわかりやすい表示名。 タイトルのエイリアスを指定することもできます。
7
fieldDescription
オプション
フィールドの説明。 存在する場合は、説明のエイリアスにすることもできます。
8
dataType
(説明を参照)
フィールドの基本データタイプ ​を示します。 すべてのカスタムフィールドに必須。

dataTypeobjectに設定されている場合は、propertiesまたは$refを同じ行に定義する必要がありますが、両方を定義する必要はありません。
9
isRequired
オプション
データ取り込みにフィールドが必要かどうかを示します。
10
isArray
オプション
フィールドが指定されたdataTypeの配列であるかどうかを示します。
11
isIdentity
オプション
フィールドがID フィールドかどうかを示します。
12
identityNamespace
isIdentityがtrueの場合は必須
ID フィールドのID名前空間
13
isPrimaryIdentity
オプション
フィールドがスキーマのプライマリ IDであるかどうかを示します。
14
minimum
オプション
(数値フィールドの場合のみ)フィールドの最小値。
15
maximum
オプション
(数値フィールドの場合のみ)フィールドの最大値。
16
enum
オプション
フィールドの列挙値のリスト。配列として表されます(例:[value1,value2,value3])。
17
stringPattern
オプション
(文字列フィールドの場合のみ)データ取り込み中に検証を渡すために、文字列値が一致する必要がある正規表現パターン。
18
format
オプション
(文字列フィールドの場合のみ)文字列フィールドの形式。
19
minLength
オプション
(文字列フィールドの場合のみ)文字列フィールドの最小長。
20
maxLength
オプション
(文字列フィールドの場合のみ)文字列フィールドの最大長。
21
properties
(説明を参照)
dataTypeobjectに設定され、$refが定義されていない場合は必須です。 これにより、オブジェクト本文がJSON文字列として定義されます(例:{"myField": {"type": "string"}})。
22
$ref
(説明を参照)
dataTypeobjectに設定され、propertiesが定義されていない場合は必須です。 これにより、オブジェクトタイプの参照オブジェクトの$idが定義されます(例:https://ns.adobe.com/xdm/context/person)。
23
comment
オプション
isIgnoredtrueに設定されている場合、この列を使用してスキーマのヘッダー情報を提供します。

CSV ファイルの形式を決定するには、次のCSV テンプレート ​を参照してください。

CSV ファイルからのエクスポートペイロードの作成

CSV テンプレートを設定したら、ファイルを/rpc/csv2schema エンドポイントに送信し、書き出しペイロードに変換できます。

API 形式

POST /rpc/csv2schema

リクエスト

リクエストペイロードでは、フォームデータを形式として使用する必要があります。 必須フォームフィールドを以下に示します。

curl -X POST \
  https://platform.adobe.io/data/foundation/schemaregistry/rpc/csv2schema \
  -H 'Authorization: Bearer {ACCESS_TOKEN}' \
  -H 'x-api-key: {API_KEY}' \
  -H 'x-gw-ims-org-id: {IMS_ORG}' \
  -H 'x-sandbox-name: {SANDBOX_NAME}' \
  -F 'csv-file=@"/Users/userName/Documents/sample-csv-template.csv"' \
  -F 'schema-class-id="https://ns.adobe.com/xdm/context/profile"' \
  -F 'schema-name="Example Schema"' \
  -F 'schema-description="Example schema description."'
プロパティ
説明
csv-file
ローカルマシンに保存されているCSV テンプレートへのパス。
schema-class-id
このスキーマが使用するXDM ​ クラス ​$idです。
schema-name
スキーマの表示名。
schema-description
スキーマの説明。

応答

応答が成功すると、CSV ファイルから生成されたエクスポートペイロードが返されます。 ペイロードは配列の形式を取り、各配列項目はスキーマの依存XDM コンポーネントを表すオブジェクトです。 CSV ファイルから生成されたエクスポートペイロードの完全な例を表示するには、以下の節を選択します。

応答ペイロードの例
code language-json
[
    {
        "$id": "https://ns.adobe.com/ddgxdmint/mixins/68397e9293a6904b3006311fb46c9573a8aaad49780dd65a",
        "$schema": "http://json-schema.org/draft-06/schema#",
        "type": "object",
        "meta:xdmType": "object",
        "meta:resourceType": "mixins",
        "title": "Generated field group 68397e9293a6904b3006311fb46c9573a8aaad49780dd65a",
        "description": "Generated field group 68397e9293a6904b3006311fb46c9573a8aaad49780dd65a",
        "meta:intendedToExtend": [
            "https://ns.adobe.com/xdm/context/profile"
        ],
        "required": [
            "_ddgxdmint"
        ],
        "properties": {
            "_ddgxdmint": {
                "properties": {
                    "customField1": {
                        "type": "string",
                        "title": "my custom field1",
                        "description": "Sample custom field1"
                    },
                    "customField2": {
                        "properties": {
                            "customerField22": {
                                "type": "string",
                                "title": "my custom field22",
                                "description": "Sample custom field22"
                            }
                        },
                        "type": "object",
                        "required": [
                            "customerField22"
                        ]
                    },
                    "customField3": {
                        "type": "number",
                        "title": "my custom field3",
                        "description": "Sample custom field3",
                        "minimum": 0,
                        "maximum": 10
                    },
                    "customField4": {
                        "type": "string",
                        "title": "my custom field4",
                        "description": "Sample custom field4",
                        "enum": [
                            "one",
                            "two",
                            "three"
                        ]
                    },
                    "customField5": {
                        "type": "array",
                        "title": "my custom field5",
                        "description": "Sample custom field5",
                        "items": {
                            "type": "string"
                        }
                    },
                    "customField6": {
                        "type": "string",
                        "title": "my custom field6",
                        "description": "Sample custom field6",
                        "format": "date"
                    }
                },
                "type": "object",
                "required": [
                    "customField1",
                    "customField2"
                ]
            }
        }
    },
    {
        "$id": "https://ns.adobe.com/ddgxdmint/mixins/7d4edf1a4c2b8c97d31f9931a10618e0b7341cefc97edad6",
        "$schema": "http://json-schema.org/draft-06/schema#",
        "type": "object",
        "meta:xdmType": "object",
        "meta:resourceType": "mixins",
        "title": "SampleFieldGroup",
        "description": "Generated field group 7d4edf1a4c2b8c97d31f9931a10618e0b7341cefc97edad6",
        "meta:intendedToExtend": [
            "https://ns.adobe.com/xdm/context/profile"
        ],
        "properties": {
            "_ddgxdmint": {
                "properties": {
                    "customField7": {
                        "type": "object",
                        "title": "my custom field7",
                        "description": "Sample custom field7",
                        "properties": {
                            "myField": {
                                "type": "string"
                            }
                        }
                    },
                    "customField8": {
                        "type": "array",
                        "title": "my custom field8",
                        "description": "Sample custom field8",
                        "items": {
                            "type": "object",
                            "$ref": "https://ns.adobe.com/xdm/context/person"
                        }
                    }
                },
                "type": "object"
            }
        }
    },
    {
        "$id": "https://ns.adobe.com/ddgxdmint/mixins/6420020c79930a4c3aa7c9fd03b218e0e85c9a7d9990ecf",
        "$schema": "http://json-schema.org/draft-06/schema#",
        "type": "object",
        "meta:xdmType": "object",
        "meta:resourceType": "mixins",
        "title": "Demographic Details:Generated field group 6420020c79930a4c3aa7c9fd03b218e0e85c9a7d9990ecf",
        "description": "Generated field group 6420020c79930a4c3aa7c9fd03b218e0e85c9a7d9990ecf",
        "meta:intendedToExtend": [
            "https://ns.adobe.com/xdm/context/profile"
        ],
        "meta:extends": [
            "https://ns.adobe.com/xdm/context/profile-person-details"
        ],
        "allOf": [
            {
                "properties": {
                    "person": {
                        "properties": {
                            "name": {
                                "properties": {
                                    "_ddgxdmint": {
                                        "properties": {
                                            "nickName": {
                                                "type": "string"
                                            }
                                        },
                                        "type": "object",
                                        "required": [
                                            "nickName"
                                        ]
                                    }
                                },
                                "type": "object",
                                "required": [
                                    "_ddgxdmint"
                                ]
                            }
                        },
                        "type": "object",
                        "required": [
                            "name"
                        ]
                    }
                },
                "required": [
                    "person"
                ]
            },
            {
                "$ref": "https://ns.adobe.com/xdm/context/profile-person-details"
            }
        ]
    },
    {
        "$id": "https://ns.adobe.com/ddgxdmint/mixins/39e6bb291e5b9072878c5c80c0ff5a325df79385ed10d241",
        "$schema": "http://json-schema.org/draft-06/schema#",
        "type": "object",
        "meta:xdmType": "object",
        "meta:resourceType": "mixins",
        "title": "Loyalty Details:Generated field group 39e6bb291e5b9072878c5c80c0ff5a325df79385ed10d241",
        "description": "Generated field group 39e6bb291e5b9072878c5c80c0ff5a325df79385ed10d241",
        "meta:intendedToExtend": [
            "https://ns.adobe.com/xdm/context/profile"
        ],
        "meta:extends": [
            "https://ns.adobe.com/xdm/mixins/profile/profile-loyalty-details"
        ],
        "allOf": [
            {
                "properties": {
                    "loyalty": {
                        "properties": {
                            "_ddgxdmint": {
                                "properties": {
                                    "joinDate": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "type": "object"
                    }
                }
            },
            {
                "$ref": "https://ns.adobe.com/xdm/mixins/profile/profile-loyalty-details"
            }
        ]
    },
    {
        "$id": "https://ns.adobe.com/ddgxdmint/schemas/632cb76723ce2fd3876385168c03eb5201c5997f3f367a2f",
        "$schema": "http://json-schema.org/draft-06/schema#",
        "type": "object",
        "meta:xdmType": "object",
        "meta:resourceType": "schemas",
        "title": "My Sample Schema",
        "description": "My Sample Schema",
        "meta:extends": [
            "https://ns.adobe.com/xdm/context/profile"
        ],
        "allOf": [
            {
                "$ref": "https://ns.adobe.com/xdm/context/profile"
            },
            {
                "$ref": "https://ns.adobe.com/ddgxdmint/mixins/68397e9293a6904b3006311fb46c9573a8aaad49780dd65a"
            },
            {
                "$ref": "https://ns.adobe.com/ddgxdmint/mixins/7d4edf1a4c2b8c97d31f9931a10618e0b7341cefc97edad6"
            },
            {
                "$ref": "https://ns.adobe.com/ddgxdmint/mixins/6420020c79930a4c3aa7c9fd03b218e0e85c9a7d9990ecf",
                "meta:refProperty": [
                    "/person/name/firstName",
                    "/person/name/lastName",
                    "/person/name/_ddgxdmint/nickName"
                ]
            },
            {
                "$ref": "https://ns.adobe.com/ddgxdmint/mixins/39e6bb291e5b9072878c5c80c0ff5a325df79385ed10d241"
            }
        ]
    },
    {
        "@type": "xdm:alternateDisplayInfo",
        "meta:resourceType": "descriptors",
        "xdm:sourceSchema": "https://ns.adobe.com/ddgxdmint/schemas/632cb76723ce2fd3876385168c03eb5201c5997f3f367a2f",
        "xdm:sourceVersion": 1,
        "xdm:sourceProperty": "/person/name/firstName",
        "xdm:title": {
            "en_us": "My first name"
        }
    },
    {
        "@type": "xdm:descriptorIdentity",
        "meta:resourceType": "descriptors",
        "xdm:sourceSchema": "https://ns.adobe.com/ddgxdmint/schemas/632cb76723ce2fd3876385168c03eb5201c5997f3f367a2f",
        "xdm:sourceVersion": 1,
        "xdm:sourceProperty": "/_ddgxdmint/customField1",
        "xdm:namespace": "email",
        "xdm:property": "xdm:code",
        "xdm:isPrimary": true
    }
]

スキーマペイロードの読み込み

CSV ファイルから書き出しペイロードを生成した後、そのペイロードを/rpc/import エンドポイントに送信してスキーマを生成できます。

エクスポートペイロードからスキーマを生成する方法について詳しくは、​ インポートエンドポイントガイド ​を参照してください。

recommendation-more-help
experience-platform-help-xdm