すべてのメタデータテンプレートのリストの取得

ガイド メタデータ メタデータの操作 すべてのメタデータテンプレートのリストの取得

すべてのメタデータテンプレートのリストの取得

会社には、ユーザーが独自に作成しなくてもすぐに使用できるメタデータテンプレートのリストがすでに存在することがよくあります。

一般に、メタデータテンプレートには、自社のみで使用できるものと、Boxを使用するすべての会社が使用できるものがあります。テンプレートのscopeにより、テンプレートはすべての人が利用可能か (global)、自社のみで利用可能か (enterprise) が定義されます。

メタデータのスコープの詳細を確認する

テンプレートのリストの取得

すべてのユーザーが使用できるグローバルテンプレートはいくつかあります。

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/global" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
.NET
BoxEnterpriseMetadataTemplateCollection<BoxMetadataTemplate> templates = await client.MetadataManager
    .GetEnterpriseMetadataAsync("global");
Java
Iterable<MetadataTemplate> templates = MetadataTemplate.getEnterpriseMetadataTemplates('global', api);
for (MetadataTemplate templateInfo : templates) {
    // Do something with the metadata template.
}
Python
templates = client.get_metadata_templates(scope='global)
for template in templates:
    print(f'Metadata template {template.templateKey} is in global scope')
Node
client.metadata.getTemplates('global')
	.then(templates => {
		// ...
	});
iOS
let iterator = client.metadata.listEnterpriseTemplates(scope: "global")
iterator.next { results in
    switch results {
    case let .success(page):
        for template in page.entries {
            print("Template name: \(template.displayName)")
        }

    case let .failure(error):
        print(error)
    }
}

これらのテンプレートの多くはBoxの内部使用を目的としたものですが、アプリケーションでこれらを使用したり適用したりすることもできます。会社のニーズに固有のデータを保持するには、社内のアプリケーションや管理者が作成したテンプレートがより便利です。

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/enterprise" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
.NET
BoxEnterpriseMetadataTemplateCollection<BoxMetadataTemplate> templates = await client.MetadataManager
    .GetEnterpriseMetadataAsync();
Java
Iterable<MetadataTemplate> templates = MetadataTemplate.getEnterpriseMetadataTemplates(api);
for (MetadataTemplate templateInfo : templates) {
    // Do something with the metadata template.
}
Python
templates = client.get_metadata_templates()
for template in templates:
    print(f'Metadata template {template.templateKey} is in enterprise scope')
Node
client.metadata.getTemplates('enterprise')
	.then(templates => {
		/* templates -> {
			limit: 100,
			entries: 
			[ { templateKey: 'documentFlow',
				scope: 'enterprise_12345',
				displayName: 'Document Flow',
				hidden: false,
				fields: 
					[ { type: 'string',
						key: 'currentDocumentStage',
						displayName: 'Current Document Stage',
						hidden: false }
					{ type: 'string',
						key: 'needsApprovalFrom',
						displayName: 'Needs Approval From',
						hidden: false },
					{ type: 'string',
						key: 'nextDocumentStage',
						displayName: 'Next Document Stage',
						hidden: false }
					{ type: 'float',
						key: 'maximumDaysAllowedInCurrentStage',
						displayName: 'Maximum Days Allowed In Current Stage',
						hidden: false }
				{ templateKey: 'marketingCollateral',
				scope: 'enterprise_12345',
				displayName: 'Marketing Collateral',
				hidden: false,
				fields: 
					[ { type: 'string',
						key: 'audience1',
						displayName: 'Audience',
						hidden: false },
					{ type: 'string',
						key: 'previousState',
						displayName: 'Previous State',
						hidden: false } ] },
				{ templateKey: 'productInfo',
				scope: 'enterprise_12345',
				displayName: 'Product Info',
				hidden: false,
				fields: 
					[ { type: 'float',
						key: 'skuNumber',
						displayName: 'SKU Number',
						hidden: false },
					{ type: 'enum',
						key: 'department',
						displayName: 'Department',
						hidden: false,
						options: 
						[ { key: 'Beauty' },
						{ key: 'Shoes' },
						{ key: 'Accessories' },
						{ key: 'Clothing' },
						{ key: 'Handbags' },
						{ key: 'Bedding' },
						{ key: 'Watches' } ] },
					{ type: 'date',
						key: 'displayDate',
						displayName: 'Display Date',
						hidden: false } ] } ],
			next_marker: null,
			prev_marker: null }
		*/
	});
iOS
let iterator = client.metadata.listEnterpriseTemplates(scope: "enterprise")
iterator.next { results in
    switch results {
    case let .success(page):
        for template in page.entries {
            print("Template name: \(template.displayName)")
        }

    case let .failure(error):
        print(error)
    }
}

メタデータテンプレート

メタデータテンプレートには、ファイルまたはフォルダに割り当てることができる一連のキー/値ペアが記載されています。

たとえば、customerInfoテンプレートは顧客に関するデータを保持しており、顧客名と顧客の業種のフィールドがあるとします。

{
  "id": "100ac693-a468-4b37-9535-05984b804dc2",
  "type": "metadata_template",
  "templateKey": "customerInfo",
  "scope": "enterprise_12345",
  "displayName": "Customer Info",
  "hidden": false,
  "copyInstanceOnItemCopy": false,
  "fields": [
    {
      "id": "5c6a5906-003b-4654-9deb-472583fc2930",
      "type": "string",
      "key": "name",
      "displayName": "Name",
      "hidden": false
    },
    {
      "id": "cf3eb5b8-52ef-456c-b175-44354a27e289",
      "type": "enum",
      "key": "industry",
      "displayName": "Industry",
      "options": [
        {"key": "Technology"},
        {"key": "Healthcare"},
        {"key": "Legal"}
      ],
      "hidden": false
    }
  ]
}