> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# コネクションの作成

> コネクションの作成は JWT を検証し、ユーザーをリダイレクトする URL を含む文字列を返します。

コネクションの作成は、Connect AI Embed 製品からコネクション作成フローをリクエストします。コネクションの作成は JWT を検証し、ユーザーをリダイレクトする URL を含む文字列を返します。パラメータ `dataSource` を指定した場合、URL はそのデータソースの **Add Connection** ページにユーザーをリダイレクトします。`dataSource` を省略した場合、URL はコネクション一覧から追加するコネクションをユーザーが選択できる汎用の **Add Connection** ページにリダイレクトします。

コネクションの作成が成功した場合のフローは次のとおりです。

<Steps>
  <Step>
    コネクションの作成リクエストが成功すると、CData がホストする **Add Connection** ページへの URL が生成されます。リクエストボディの `redirectURL` は、**Add Connection** ページの **Return to** ボタンに対応します。
  </Step>

  <Step>
    ユーザーが **Save & Test** をクリックします。内部 API レスポンスには、CData がホストする **Add Connection** ページへのコネクション詳細が含まれます。
  </Step>

  <Step>
    ユーザーが **Return to** をクリックします。コネクション情報はパラメータとしてリダイレクト URL に追加されます。

    パラメータには以下が含まれます。

    * `cdata_connection_id` – コネクションの一意の ID。
    * `cdata_connection_name` – `Salesforce1` などのコネクション名。
    * `cdata_connection_status` – コネクションのステータス。値は `success`、`error`（接続エラー）、または `none`（接続が行われなかった）です。
  </Step>
</Steps>

例 1: **Save & Test** が成功した後の URL:

```text wrap theme={null}
https://www.google.com/?cdata_connection_id=da77460c-7438-4288-be66-ea0059c160ae&cdata_connection_name=OData1&cdata_connection_status=success&zx=1773244250880&no_sw_cr=1
```

例 2: ユーザーが **Return to** をクリックし、**Save & Test** を実行しなかった場合の URL:

```text wrap theme={null}
https://www.google.com/?cdata_connection_status=none&zx=1773252769892&no_sw_cr=1
```

例 3: 保存後にテストが失敗した場合の URL:

```text wrap theme={null}
https://www.google.com/?cdata_connection_id=507b42e8-94b1-488e-a1d8-5a62d5d74a31&cdata_connection_name=Salesforce1&cdata_connection_status=error&zx=1773252951878&no_sw_cr=1
```


## OpenAPI

````yaml ja/API/REST-API-Embedded.yaml POST /poweredby/connection/create
openapi: 3.1.0
info:
  title: CData Connect AI REST API Embedded
  version: v1
servers:
  - url: https://cloud.cdata.com/api
    description: Production base URL
security:
  - BearerAuth: []
paths:
  /poweredby/connection/create:
    post:
      tags:
        - Connection
      summary: Create Connection
      description: >
        Create Connection requests the Connection Create Flow from the Connect
        AI Embed product. Create Connection validates the JWT and returns a
        string containing the URL to redirect the user to. If you include the
        parameter `dataSource`, the URL redirects the user to an **Add
        Connection** page for the data source. If you omit `dataSource`, the URL
        redirects the user to a general **Add Connection** page where the user
        can select a connection to add from the connections list.
      operationId: createConnection
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateConnectionRequest'
            example:
              dataSource: ExcelOnline
              redirectURL: https://www.google.com
              name: ExcelConnection
              externalId: acme-excel-001
      responses:
        '200':
          description: >-
            A string containing the CData-hosted connection URL to redirect the
            user to.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RedirectURLResponse'
              example:
                redirectURL: >-
                  https://cloud.cdata.com/oem/user/connections/edit?token=eyJhbGciOiJSUzI1NiIs...truncated...&driver=ExcelOnline&redirectUrl=https%3A%2F%2Fwww.google.com
components:
  schemas:
    CreateConnectionRequest:
      type: object
      required:
        - redirectURL
      properties:
        dataSource:
          type: string
          description: >-
            (Optional) The type of data source (For example: Snowflake, ActOn,
            or Salesforce). You can obtain data source names from List
            Connections. If you omit this parameter, the user can select from a
            list of available data sources.
          nullable: true
        redirectURL:
          type: string
          description: >-
            The URL to redirect the customer once the customer has created the
            connection through the Connect AI UI. This URL maps to the **Return
            to** button on the **Add Connection** page in the Connect AI UI.
        name:
          type: string
          description: >-
            (Optional) If provided, the connection name. By default, this is a
            suggested default that the end user can change on the **Add
            Connection** form. Set `editableName` to `false` to lock the field
            to this value. If `name` is provided without a `dataSource`, it is
            ignored.
          nullable: true
        externalId:
          type: string
          description: >-
            (Optional) Your identifier for this connection in your own system.
            Must be unique within the sub-account; if a connection with the same
            `externalId` already exists under the account, the request returns a
            conflict error.
          nullable: true
        editableName:
          type: boolean
          description: >-
            (Optional) The default value is `true`. When `true`, any `name` you
            supply is shown as a suggested default value, and the end user can
            change it. When `false`, the **Connection Name** field is rendered
            read-only, and the server enforces the supplied `name` on submit.
            Has no effect when `name` is omitted.
          default: true
      additionalProperties: false
    RedirectURLResponse:
      type: object
      required:
        - redirectURL
      properties:
        redirectURL:
          type: string
          description: >-
            A string containing the CData-hosted connection URL to redirect the
            user to.
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT token authentication. Include the token in the Authorization header
        as `Bearer {token}`. See
        [Authentication](/ja/API/Authentication-Embedded) for more information
        on creating a token.

````