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

# Initiate Oauth

> Initiate an OAuth authentication flow.

This endpoint generates an authorization URL that the user should visit
to grant permissions to the integration.

**Flow:**
1. Call this endpoint with the integration ID
2. Redirect the user to the returned `auth_url`
3. User grants permissions on the provider's website
4. Provider redirects back to the callback URL with a code
5. Callback handler exchanges code for tokens and creates connection

**Example:**
```json
POST /oauth/initiate
{
    "integration_id": "gmail",
    "auth_method_id": "oauth2",
    "scopes": [
        "https://www.googleapis.com/auth/gmail.readonly",
        "https://www.googleapis.com/auth/gmail.send"
    ]
}
```

**Response:**
```json
{
    "auth_url": "https://accounts.google.com/o/oauth2/v2/auth?...",
    "state": "abc123...",
    "integration_id": "gmail"
}
```



## OpenAPI

````yaml api-reference/openapi.json post /api/v1/oauth/initiate
openapi: 3.1.0
info:
  title: FastAPI app
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/oauth/initiate:
    post:
      tags:
        - OAuth
      summary: Initiate Oauth
      description: |-
        Initiate an OAuth authentication flow.

        This endpoint generates an authorization URL that the user should visit
        to grant permissions to the integration.

        **Flow:**
        1. Call this endpoint with the integration ID
        2. Redirect the user to the returned `auth_url`
        3. User grants permissions on the provider's website
        4. Provider redirects back to the callback URL with a code
        5. Callback handler exchanges code for tokens and creates connection

        **Example:**
        ```json
        POST /oauth/initiate
        {
            "integration_id": "gmail",
            "auth_method_id": "oauth2",
            "scopes": [
                "https://www.googleapis.com/auth/gmail.readonly",
                "https://www.googleapis.com/auth/gmail.send"
            ]
        }
        ```

        **Response:**
        ```json
        {
            "auth_url": "https://accounts.google.com/o/oauth2/v2/auth?...",
            "state": "abc123...",
            "integration_id": "gmail"
        }
        ```
      operationId: initiate_oauth_api_v1_oauth_initiate_post
      parameters:
        - name: X-Workspace-Id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: The workspace ID
            title: X-Workspace-Id
          description: The workspace ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAuthInitiateRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - DualAuthScheme: []
components:
  schemas:
    OAuthInitiateRequest:
      properties:
        integration_id:
          type: string
          title: Integration Id
        auth_method_id:
          type: string
          title: Auth Method Id
          default: oauth2
        scopes:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Scopes
        redirect_uri:
          anyOf:
            - type: string
            - type: 'null'
          title: Redirect Uri
      type: object
      required:
        - integration_id
      title: OAuthInitiateRequest
      description: Request to initiate OAuth flow.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    DualAuthScheme:
      type: http
      scheme: bearer

````