# APIを使ったデータモデルの作成

利用対象...

* Cloud API Services Platform
* Cloud Big Data
* Cloud Big Data Platform
* Cloud Data Fabric
* Cloud Data Integration
* Cloud Data Management Platform
* Cloud Pipeline Designer Standard Edition
* Data Fabric
* Qlik Talend Cloud Enterprise Edition

データモデルは属性のリストで構成されています。データモデルの作成はキャンペーンの作成より前に行われる必要があります。

この例ではリクエストの送信でTalend API Testerが使われます。

Talend API Testerの詳細は、[Talend Cloud API Testerユーザーガイド](https://help.qlik.com/talend/r/ja-JP/Cloud/api-tester-user-guide)をご覧ください。

## 手順

1. パーソナルアクセストークンがまだない場合は1つ生成します。詳細は、[パーソナルアクセストークンを生成](https://help.qlik.com/talend/r/ja-JP/Cloud/management-console-user-guide/cloud-access-token)をご覧ください。
2. ブラウザーでTalend API Testerを開きます。
3. [Repository] (リポジトリー)タブの[Method] (メソッド)ドロップダウンリストで、Postを選択します。
4. https://tds.{region}.cloud.talend.com/schemaservice/api/v1/schemas/org.talend.schemaというURLを入力します。

   各データセンターで使用するURLのリストは、[Talend Cloudのアプリケーションにアクセス](https://help.qlik.com/talend/ja-JP/installation-guide-windows/Cloud/talend-cloud-application-url)で確認できます。
5. [Add hearder] (ヘッダーの追加)ボタンをクリックし、[name] (名前)フィールドに Authorizationと、そして[value] (値)フィールドにBearerに続けて空白スペースと自分のトークンを入力します。
6. [Add header] (ヘッダーの追加)ボタンをクリックし、[name] (名前)フィールドにCookieと入力します。[value] (値)フィールドを空のままにしておきます。
7. [Body] (ボディ)フィールドに、JSONによるデータモデル詳細を含めます。
   ### 例

   ガイドツアーのものと同じ demo\_productデータモデルを作成する場合は、別の名前(my\_products\_created\_via\_APIなど)を使って次のように入力します:
   ```
   {
       "name": "my_products_created_via_API",
       "displayName": "Product (created via API)",
       "description": "Product catalog available.",
       "fields": [{
           "name": "Id",
           "displayName": "Id",
           "description": "",
           "type": "integer",
           "required": true
       }, {
           "name": "Name",
           "displayName": "Name",
           "description": "",
           "type": "text",
           "required": true
       }, {
           "name": "Material",
           "displayName": "Material",
           "description": "",
           "type": "text",
           "required": true
       }, {
           "name": "Size",
           "displayName": "Size",
           "description": "",
           "type": "text",
           "required": true
       }, {
           "name": "Price",
           "displayName": "Price",
           "description": "",
           "type": "decimal",
           "required": true,
           "constraints": [{
               "name": "scaleDecimal",
               "value": 2
           }]
       }, {
           "name": "Quantity",
           "displayName": "Quantity",
           "description": "",
           "type": "integer",
           "required": true
       }, {
           "name": "Family",
           "displayName": "Family",
           "description": "",
           "type": "text",
           "required": true
       }, {
           "name": "Packaging",
           "displayName": "Packaging",
           "description": "",
           "type": "text",
           "required": true
       }, {
           "name": "ProductURL",
           "displayName": "Product URL",
           "description": "",
           "type": "URL",
           "required": true
       }, {
           "name": "productType",
           "displayName": "Type",
           "description": "",
           "type": "text",
           "required": false
       }]
   }
   ```
8. [Send] (送信)をクリックします。

## タスクの結果

リクエストが成功したことを表す200 HTTPコードがAPIによって返されます。この応答には、作成されたデータモデルのJSONによる説明が含まれています。例:

```
{
    "namespace": "org.talend.schema",
    "displayName": "Product (created via API)",
    "name": "my_products_created_via_API",
    "description": "Product catalog available.",
    "version": 1,
    "references":[],
    "creationDate": 1601467434441,
    "lastUpdateDate": 1601467434441,
    "createdBy": {
        "id": "3e2eed7d-c632-40da-822e-9780f2c74842",
        "username": "user@account",
        "firstName": "user",
        "lastName": "name",
        "enabled": true
    },
    "lastUpdatedBy": {
        "id": "3e2eed7d-c632-40da-822e-9780f2c74842",
        "username": "user@account",
        "firstName": "user",
        "lastName": "name",
        "enabled": true
    },
    "fields": null,
    "referenced": false
}
```

Talend Cloud Data Stewardshipで作成したデータモデルを表示できます。

情報メモ注: 作成しようとしているものと同じ名前のデータモデルが既に存在する場合は、APIによって400 Bad requestというエラーが返されます。この応答には次のようなメッセージが含まれています:

```
{"code":"SCHEMA_ALL_SCHEMA_NAME_ALREADY_EXISTS","message":"SCHEMA_NAME_ALREADY_EXISTS","context":{"name":"demo_product"}}
```