項目へのメタデータの適用
項目へのメタデータの適用
メタデータテンプレートは、項目のid
、テンプレートのtemplateKey
とscope
、およびテンプレート内の各フィールドの値のセットを使用してファイルまたはフォルダに適用できます。
ファイルへのメタデータの適用
メタデータテンプレートのインスタンスをファイルに適用するには、ファイルのfile_id
、テンプレートのscope
とtemplateKey
、および必要に応じてテンプレート内の各フィールドの値のセットを指定してPOST /files/:file_id/metadata/:scope/:templateKey
APIエンドポイントを呼び出します。
curl -i -X POST "https://api.box.com/2.0/files/12345/metadata/enterprise_27335/blueprintTemplate" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-H "content-type: application/json" \
-d '{
"audience": "internal",
"documentType": "Q1 plans",
"competitiveDocument": "no",
"status": "active",
"author": "Jones",
"currentState": "proposal"
}'
フォルダにメタデータを適用
メタデータテンプレートのインスタンスをフォルダに適用するには、フォルダのfolder_id
、テンプレートのscope
とtemplateKey
、および必要に応じてテンプレート内の各フィールドの値のセットを指定してPOST /folders/:folder_id/metadata/:scope/:templateKey
APIエンドポイントを呼び出します。
curl -i -X POST "https://api.box.com/2.0/folders/4353455/metadata/enterprise_27335/blueprintTemplate" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-H "content-type: application/json" \
-d '{
"audience": "internal",
"documentType": "Q1 plans",
"competitiveDocument": "no",
"status": "active",
"author": "Jones",
"currentState": "proposal"
}'
リクエスト本文
リクエストの本文には、テンプレート内の各フィールドの値を含めることができます。テンプレートに存在するフィールドを調べるには、メタデータテンプレートを調査してください。
たとえば、次のテンプレートについて考えましょう。
{
"id": "8120731a-41e4-11ea-b77f-2e728ce88125",
"type": "metadata_template",
"templateKey": "productInfo",
"scope": "enterprise_1234567",
"displayName": "Product Info",
"hidden": false,
"copyInstanceOnItemCopy": true,
"fields": [
{
"id": "feed71de-41e5-11ea-b77f-2e728ce88125",
"type": "string",
"key": "name",
"displayName": "Name",
"hidden": false
},
{
"id": "02b36bb6-41e6-11ea-b77f-2e728ce88125",
"type": "enum",
"key": "category",
"displayName": "Category",
"hidden": false,
"options": [
{
"id": "06a7bcc2-41e6-11ea-b77f-2e728ce88125",
"key": "SUVs"
},
{
"id": "0a50df02-41e6-11ea-b77f-2e728ce88125",
"key": "Saloons"
},
{
"id": "0e466be0-41e6-11ea-b77f-2e728ce88125",
"key": "Cabriolets"
}
]
}
]
}
このテンプレートには、2つのテンプレートフィールドとしてname
とcategory
があります。name
フィールドは通常のテキストフィールドで、category
は列挙型フィールドです。
このテンプレートをファイルまたはフォルダに割り当てるリクエストの本文には、テンプレートの任意のフィールドの値を含めることができます。本文にフィールドも値も含めないことも可能です。
この場合、次のリクエスト本文は有効な例です。
{
"name": "Model 3",
"category": "SUVs"
}