メタデータテンプレートの作成
メタデータテンプレートの作成
メタデータテンプレートを作成するには、scope
、displayName
、および必要に応じて一連のfields
をPOST /metadata_templates/schema
APIに渡します。
curl -i -X POST "https://api.box.com/2.0/metadata_templates/schema" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-H "content-type: application/json" \
-d '{
"scope": "enterprise",
"displayName": "Customer",
"fields": [
{
"type": "string",
"key": "name",
"displayName": "Name",
"description": "The customer name",
"hidden": false
},
{
"type": "date",
"key": "last_contacted_at",
"displayName": "Last Contacted At",
"description": "When this customer was last contacted at",
"hidden": false
},
{
"type": "enum",
"key": "industry",
"displayName": "Industry",
"options": [
{"key": "Technology"},
{"key": "Healthcare"},
{"key": "Legal"}
]
},
{
"type": "multiSelect",
"key": "role",
"displayName": "Contact Role",
"options": [
{"key": "Developer"},
{"key": "Business Owner"},
{"key": "Marketing"},
{"key": "Legal"},
{"key": "Sales"}
]
}
]
}'
テンプレートフィールド
fields
属性は、ユーザーがテンプレートで入力できる個々のフィールドのセットを表します。たとえば、customer
テンプレートにstring
タイプのname
フィールドがあるとします。
テンプレートフィールドは、string
、enum
、float
、date
、enum
、またはmultiSelect
タイプのいずれかになります。各フィールドには少なくともtype
、displayName
、およびkey
が必要です。
{
"scope": "enterprise",
"displayName": "Customer",
"fields": [
{
"type": "string",
"key": "name",
"displayName": "Name"
}
]
}
enum
およびmultiSelect
フィールドタイプは、ユーザーが項目のリストからそれぞれ1つまたは複数のオプションを選択できるドロップダウンリストを表します。
{
"scope": "enterprise",
"displayName": "Customer",
"fields": [
{
"type": "enum",
"key": "industry",
"displayName": "Industry",
"options": [
{"key": "Technology"},
{"key": "Healthcare"},
{"key": "Legal"}
]
}
]
}
メタデータテンプレートフィールドの詳細を確認する
テンプレートキー
メタデータテンプレートが作成されると、templateKey
を明示的に指定した場合を除き、テンプレートのdisplayName
から自動的にtemplateKey
が生成されます。テンプレートキーを作成する際に、名前に含まれるスペースと規格外の文字は削除され、文字列はキャメルケースに変換されます。
たとえば、Test Name (with-special_) Characters
という名前のメタデータテンプレートのtemplateKey
はtestNameWithspecialCharacters
になります。
その後、このテンプレートキーは、テンプレートの情報を取得したり、項目にテンプレートを割り当てたりするためのAPIリクエストを実行するときに使用されます。