Skip to main content Skip to complementary content

Creating a data model using the API

A data model consists of a list of attributes. The data model must be created before creating the campaign.

In this example, Talend API Tester is used to send requests.

For further information about Talend API Tester, see Talend Cloud API Tester User Guide.

Procedure

  1. If you do not have a personal access token yet, generate one. For further information, see Generating a Personal Access Token.
  2. Open Talend API Tester in your browser.
  3. From the Repository tab, select Post in the Method drop-down list.
  4. Enter the following URL: https://tds.{region}.cloud.talend.com/schemaservice/api/v1/schemas/org.talend.schema

    You'll find a list of the URLs to use for each data center in Accessing Talend Cloud applications.

  5. Click the Add header button and enter Authorization in the name field and Bearer followed by a whitespace and your token in the value field.
  6. Click the Add header button and enter Cookie in the name field, then leave the value field empty.
  7. In the Body field, include the data model details in JSON.

    Example

    To create the same demo_product data model as the one from the guided tour, using a different name such as my_products_created_via_API, enter:
    {
        "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. Click Send.

Results

The API returns a 200 HTTP code to inform you that the request was successful. The response includes a JSON description of the created data model, for example:
{
    "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
}

You can see the data model you created in Talend Cloud Data Stewardship.

Information noteNote: If you try to create a data model with a name that already exists, the API returns a 400 Bad request error. The response includes a message like this one:
{"code":"SCHEMA_ALL_SCHEMA_NAME_ALREADY_EXISTS","message":"SCHEMA_NAME_ALREADY_EXISTS","context":{"name":"demo_product"}}

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!