メタデータテンプレートの取得

ガイド メタデータ メタデータテンプレート メタデータテンプレートの取得

メタデータテンプレートの取得

メタデータテンプレートに関する情報を取得するには、テンプレートの名前とスコープ、またはテンプレートの識別子を使用します。

認証済みユーザーが取得できるのは、globalスコープまたはenterprise_:idスコープ (:idは会社のID) の中でスコープが設定されたメタデータテンプレートに関する情報のみです。

名前を指定してメタデータテンプレートを取得

名前を指定してメタデータテンプレートを取得するには、テンプレートのscopetemplateKeyを指定してGET /metadata_templates/:scope/:templateKey APIエンドポイントを呼び出します。

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/enterprise/blueprintTemplate/schema" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
.NET
BoxMetadataTemplate template = await client.MetadataManager
    .GetMetadataTemplate("enterprise", "marketingCollateral");
Java
MetadataTemplate template = MetadataTemplate.getMetadataTemplate(api, "templateName");
Python
template = client.metadata_template('enterprise', 'employeeRecord').get()
print(f'The {template.displayName} template has {len(template.fields)} fields')
Node
client.metadata.getTemplateSchema('enterprise', 'vcontract')
	.then(template => {
		/* template -> {
			id: '17f2d715-6acb-45f2-b96a-28b15efc9faa',
			templateKey: 'vcontract',
			scope: 'enterprise_12345',
			displayName: 'Vendor Contract',
			hidden: true,
			fields: 
			[ { type: 'date',
				key: 'signed',
				displayName: 'Date Signed',
				hidden: false },
				{ type: 'string',
				key: 'vendor',
				displayName: 'Vendor',
				hidden: false },
				{ type: 'enum',
				key: 'fy',
				displayName: 'Fiscal Year',
				options: 
					[ { key: 'FY17' },
					{ key: 'FY18' },
					{ key: 'FY19' } ],
				hidden: false } ] }
		*/
	});
iOS
client.metadata.getTemplateByKey(
    scope: "enterprise",
    templateKey: "personnelRecord"
) { (result: Result<MetadataTemplate, BoxSDKError>) in
    guard case let .success(template) = result {
        print("Error retrieving metadata template")
        return
    }

    print("Metadata template has \(template.fields?.count) fields")
}

テンプレートのscopetemplateKeyを取得するには、すべてのメタデータテンプレートのリストを取得するか、項目のすべてのインスタンスのリストを取得します。

IDを指定してメタデータテンプレートを取得

IDを指定してメタデータテンプレートを取得するには、テンプレートのscopetemplateKeyの両方をGET /metadata_templates/:id APIエンドポイントに渡す必要があります。

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/d9671692-3df6-11ea-b77f-2e728ce88125" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
.NET
BoxMetadataTemplate template = await client.MetadataManager
    .GetMetadataTemplateById("17f2d715-6acb-45f2-b96a-28b15efc9faa");
Java
MetadataTemplate template = MetadataTemplate.getMetadataTemplateByID(api, "37c0204b-3fe1-4a32-b9da-f28e88f4c4c6");
Python
template = client.metadata_template_by_id(template_id='abcdef-fba434-ace44').get()
print(f'The {template.displayName} template has {len(template.fields)} fields')
Node
client.metadata.getTemplateByID('17f2d715-6acb-45f2-b96a-28b15efc9faa')
	.then(template => {
		/* template -> {
			id: '17f2d715-6acb-45f2-b96a-28b15efc9faa',
			templateKey: 'vcontract',
			scope: 'enterprise_12345',
			displayName: 'Vendor Contract',
			hidden: true,
			fields: 
			[ { type: 'date',
				key: 'signed',
				displayName: 'Date Signed',
				hidden: false },
				{ type: 'string',
				key: 'vendor',
				displayName: 'Vendor',
				hidden: false },
				{ type: 'enum',
				key: 'fy',
				displayName: 'Fiscal Year',
				options: 
					[ { key: 'FY17' },
					{ key: 'FY18' },
					{ key: 'FY19' } ],
				hidden: false } ] }
		*/
	});
iOS
client.metadata.getTemplateById(
    id: "26004e29-7b94-44a1-8a63-f9aa384c7421"
) { (result: Result<MetadataTemplate, BoxSDKError>) in
    guard case let .success(template) = result {
        print("Error retrieving metadata template")
        return
    }

    print("Metadata template has \(template.fields?.count) fields")
}