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

# Create Connection

> This endpoint allows you to create a new connection for a specified project.

You need to provide the project ID and the connection details in the request body.

The connection details include the name, type, and credentials required for the connection.

Depending on the connection type, additional parameters may be required under credentials.

You can view the list of supported connection types by calling the /connections/config endpoint.

You can switch examples from the second dropdown of the sample request component. (cURL (first dropdown) - Stripe Connection Request (second dropdown))

**Note**: Typically, the connection creation process involves the following steps:
1. First, learn about the connection type and the required parameters by calling the /connections/config endpoint.
2. Create a connection request with the required parameters.
3. If the connection requires Oauth2 authorization, there may be additional steps to follow. See https://docs.peaka.com/how-to-guides/how-to-create-oauth2-based-connections-via-peaka for more information.

**Example**:
- POSTGRES Connection Configuration:

GET /connections/config endpoint displays all of the connection types.

GET /connection/config/POSTGRES endpoint displays the POSTGRES connection configuration.

The definition of the POSTGRES connection configuration is as follows:
``` json
    {
        "connectionType": "POSTGRES",
        "connectionTypeLabel": "PostgreSQL",
        "name": "PostgreSQL",
        "authorizationType": "custom",
        "credentialSchemaType": "postgres_credential_schema",
        "category": "Database",
        "configuration": [
            {
                "fieldName": "url",
                "fieldType": "text",
                "required": true,
                "description": "URL"
            },
            {
                "fieldName": "port",
                "fieldType": "number",
                "required": true,
                "description": "Port"
            },
            {
                "fieldName": "user",
                "fieldType": "text",
                "required": true,
                "description": "User"
            },
            {
                "fieldName": "password",
                "fieldType": "text",
                "required": true,
                "description": "Password"
            },
            {
                "fieldName": "databaseName",
                "fieldType": "text",
                "required": true,
                "description": "Database Name"
            },
            {
                "fieldName": "useSsl",
                "fieldType": "boolean",
                "required": true,
                "description": "Use SSL"
            }
        ],
        "documentationUrl": "https://docs.peaka.com/integrations/postgresql"
    }
```

According to the POSTGRES connection configuration, the connection request should include the following parameters (respecting to the required flag):
- url: URL of the host IP or domain
- port: Port number
- user: User of the database
- password: Password of the user
- databaseName: Name of the database
- useSsl: Boolean value to indicate whether to use SSL

``` json
{
    "name": "examplePostgre",
    "type": "POSTGRES",
    "credential": {
        "url": "<host ip or domain>",
        "port": 5432,
        "user": "userOfYourDB",
        "password": "passwordOfUser",
        "databaseName": "yourDBName",
        "useSsl": false
    }
}
```



<span style={{display: "flex", gap: "10px", flexDirection: "row", alignItems: "center"}}>
  <img src="https://cdn.peaka.com/badges/partner-api-key-badge.png" />

  <img src="https://cdn.peaka.com/badges/project-api-key-badge.png" />
</span>


## OpenAPI

````yaml post /connections/{projectId}
openapi: 3.0.1
info:
  title: Peaka Gateway API
  description: Peaka Gateway API Documentation
  version: '1.0'
servers:
  - url: https://partner.peaka.studio/api/v1
    description: Default Server URL (US Zone)
  - url: https://partner.eu.peaka.studio/api/v1
    description: EU Zone
security:
  - bearerAuth: []
paths:
  /connections/{projectId}:
    post:
      tags:
        - Connections
      summary: Create Connection
      description: >+
        This endpoint allows you to create a new connection for a specified
        project.


        You need to provide the project ID and the connection details in the
        request body.


        The connection details include the name, type, and credentials required
        for the connection.


        Depending on the connection type, additional parameters may be required
        under credentials.


        You can view the list of supported connection types by calling the
        /connections/config endpoint.


        You can switch examples from the second dropdown of the sample request
        component. (cURL (first dropdown) - Stripe Connection Request (second
        dropdown))


        **Note**: Typically, the connection creation process involves the
        following steps:

        1. First, learn about the connection type and the required parameters by
        calling the /connections/config endpoint.

        2. Create a connection request with the required parameters.

        3. If the connection requires Oauth2 authorization, there may be
        additional steps to follow. See
        https://docs.peaka.com/how-to-guides/how-to-create-oauth2-based-connections-via-peaka
        for more information.


        **Example**:

        - POSTGRES Connection Configuration:


        GET /connections/config endpoint displays all of the connection types.


        GET /connection/config/POSTGRES endpoint displays the POSTGRES
        connection configuration.


        The definition of the POSTGRES connection configuration is as follows:

        ``` json
            {
                "connectionType": "POSTGRES",
                "connectionTypeLabel": "PostgreSQL",
                "name": "PostgreSQL",
                "authorizationType": "custom",
                "credentialSchemaType": "postgres_credential_schema",
                "category": "Database",
                "configuration": [
                    {
                        "fieldName": "url",
                        "fieldType": "text",
                        "required": true,
                        "description": "URL"
                    },
                    {
                        "fieldName": "port",
                        "fieldType": "number",
                        "required": true,
                        "description": "Port"
                    },
                    {
                        "fieldName": "user",
                        "fieldType": "text",
                        "required": true,
                        "description": "User"
                    },
                    {
                        "fieldName": "password",
                        "fieldType": "text",
                        "required": true,
                        "description": "Password"
                    },
                    {
                        "fieldName": "databaseName",
                        "fieldType": "text",
                        "required": true,
                        "description": "Database Name"
                    },
                    {
                        "fieldName": "useSsl",
                        "fieldType": "boolean",
                        "required": true,
                        "description": "Use SSL"
                    }
                ],
                "documentationUrl": "https://docs.peaka.com/integrations/postgresql"
            }
        ```


        According to the POSTGRES connection configuration, the connection
        request should include the following parameters (respecting to the
        required flag):

        - url: URL of the host IP or domain

        - port: Port number

        - user: User of the database

        - password: Password of the user

        - databaseName: Name of the database

        - useSsl: Boolean value to indicate whether to use SSL


        ``` json

        {
            "name": "examplePostgre",
            "type": "POSTGRES",
            "credential": {
                "url": "<host ip or domain>",
                "port": 5432,
                "user": "userOfYourDB",
                "password": "passwordOfUser",
                "databaseName": "yourDBName",
                "useSsl": false
            }
        }

        ```

      operationId: createConnection
      parameters:
        - name: projectId
          in: path
          description: ID of the project
          required: true
          schema:
            type: string
          example: mtKDhe1U
      requestBody:
        description: Connection Request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConnectionRequest'
            examples:
              Stripe Connection Request:
                description: Sample Stripe Connection parameters
                value:
                  name: exampleStripeConnection21
                  type: stripe
                  credential:
                    token: <stripeToken>
              'Connection (Oauth2) Request With Redirect Url ':
                description: Sample Oauth2 Connection with redirect url parameters
                value:
                  name: exampleOauthConnection
                  type: google_analytics
                  credential:
                    clientId: <googleOauthAppClientId>
                    clientSecret: <googleOauthAppClientSecret>
                  connectionCallback: <connectionCallbackUrl>
              HubSpot Connection (Oauth2) Request:
                description: Sample HubSpot Connection parameters
                value:
                  name: exampleHubspotConnection
                  type: hubspot
                  credential:
                    clientId: <hubspotOauthAppClientId>
                    clientSecret: <hubspotOauthAppClientSecret>
                    refreshToken: <OauthRefreshToken>
              AirTable Connection Request:
                description: Sample AirTable Connection parameters
                value:
                  name: exampleAirtableConnection
                  type: airtable
                  credential:
                    personalAccessToken: <yourAirtableApiKey>
              PostgreSQL Connection Request:
                description: PostgreSQL Connection Request
                value:
                  name: examplePostgre
                  type: POSTGRES
                  credential:
                    url: <host ip or domain>
                    port: 5432
                    user: userOfYourDB
                    password: passwordOfUser
                    databaseName: yourDBName
                    useSsl: false
        required: true
      responses:
        '200':
          description: Connection created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Connection'
              examples:
                Successful Stripe Connection:
                  description: Sample Stripe Connection
                  value:
                    id: 6243f42a-42d0-4821-a90f-763cda6cda50
                    name: exampleStripeConnection21
                    type: stripe
components:
  schemas:
    ConnectionRequest:
      type: object
      properties:
        name:
          type: string
          description: Name of the connection given by the user
        type:
          type: string
          description: |-
            Type of connection.
             
             Example: airtable for AirTable, stripe for Stripe, hubspot_access_token for HubSpot (with Access Token), etc.

             Exact list can be fetched by following url: /connections/config
        credential:
          type: object
          additionalProperties: true
          description: >
            Credential object for the connection.


            Its structure is dependent on the connection type and can be fetched
            by following url: /connections/config
        connectionCallback:
          type: string
          description: The url to redirect to after an oauth connection is established.
    Connection:
      type: object
      properties:
        id:
          type: string
          description: Connection ID
        name:
          type: string
          description: Name of the connection
        type:
          type: string
          description: >
            Type of connection.


            Example: airtable for AirTable, stripe for Stripe,
            hubspot_access_token for HubSpot (with Access Token), etc.


            Exact list can be fetched by following url: /connections/config
        url:
          type: string
          description: |
            Oauth callback url if the connection is Oauth based.
  securitySchemes:
    bearerAuth:
      type: http
      description: >-
        Use the Authorization header with the value 'Bearer <apiKey>' to
        authenticate. Partner API Keys have full access; Project API Keys are
        limited to their project scope. Learn more:
        https://docs.peaka.com/api-reference/authentication
      scheme: bearer
      bearerFormat: Api Key

````