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

# Connect repository and environments

> Connect repository and environments through the Towbar REST API.

Required permissions: repository.connect. Personal keys are capped by their owner’s current team role.

See [request conventions](/docs/api/overview) and [automation workflows](/docs/api/workflows). MCP clients use the task-oriented [tool catalogue](/docs/api/mcp-tools).


## OpenAPI

````yaml api-reference/openapi.json POST /sources/connect
openapi: 3.1.0
info:
  title: Towbar API
  version: 2.0.0
  description: >-
    Manage your Towbar control plane with a bearer API key. Keys inherit current
    workspace permissions.
servers:
  - url: https://api.example.com/v1/api
security: []
paths:
  /sources/connect:
    post:
      tags:
        - Repositories / Sync & manifest
      summary: Connect repository and environments
      description: >-
        Required permissions: repository.connect. Personal keys are capped by
        the current member role; team keys use explicit grants.
      operationId: post_sources_connect
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $schema: https://json-schema.org/draft/2020-12/schema
              anyOf:
                - type: object
                  properties:
                    repositoryOwner:
                      type: string
                      minLength: 1
                      maxLength: 255
                    repositoryName:
                      type: string
                      minLength: 1
                      maxLength: 255
                    environments:
                      minItems: 1
                      type: array
                      items:
                        type: object
                        properties:
                          environment:
                            type: string
                            pattern: ^[a-z][a-z0-9-]{0,62}$
                          branch:
                            type: string
                            minLength: 1
                            maxLength: 255
                        required:
                          - environment
                          - branch
                        additionalProperties: false
                    provider:
                      default: github
                      type: string
                      const: github
                    githubInstallationId:
                      type: string
                      format: uuid
                      pattern: >-
                        ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                  required:
                    - repositoryOwner
                    - repositoryName
                    - environments
                    - githubInstallationId
                  additionalProperties: false
                - type: object
                  properties:
                    repositoryOwner:
                      type: string
                      minLength: 1
                      maxLength: 255
                    repositoryName:
                      type: string
                      minLength: 1
                      maxLength: 255
                    environments:
                      minItems: 1
                      type: array
                      items:
                        type: object
                        properties:
                          environment:
                            type: string
                            pattern: ^[a-z][a-z0-9-]{0,62}$
                          branch:
                            type: string
                            minLength: 1
                            maxLength: 255
                        required:
                          - environment
                          - branch
                        additionalProperties: false
                    provider:
                      type: string
                      const: gitlab
                    providerRepositoryId:
                      type: string
                      pattern: ^[1-9]\d{0,19}$
                    integration:
                      type: string
                      minLength: 1
                      maxLength: 64
                      pattern: ^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$
                  required:
                    - repositoryOwner
                    - repositoryName
                    - environments
                    - provider
                    - providerRepositoryId
                    - integration
                  additionalProperties: false
      responses:
        '201':
          description: Source, connected environments and initial sync outcomes.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Response_348'
                  - type: object
                    properties:
                      localization:
                        $schema: https://json-schema.org/draft/2020-12/schema
                        type: object
                        properties:
                          dateFormat:
                            type: string
                            enum:
                              - day-short-month-year
                              - short-month-day-year
                              - year-month-day
                              - day-month-year
                              - month-day-year
                          timeFormat:
                            type: string
                            enum:
                              - 24-hour
                              - 12-hour
                              - 24-hour-seconds
                              - 12-hour-seconds
                          timeZone:
                            type: string
                          timestamps:
                            type: object
                            propertyNames:
                              type: string
                            additionalProperties:
                              type: object
                              properties:
                                date:
                                  type: string
                                time:
                                  type:
                                    - string
                                    - 'null'
                                dateTime:
                                  type:
                                    - string
                                    - 'null'
                                timeZone:
                                  type: string
                                zoneLabel:
                                  type: string
                                epochMilliseconds:
                                  type: number
                                inputDateTime:
                                  type:
                                    - string
                                    - 'null'
                              required:
                                - date
                                - time
                                - dateTime
                                - timeZone
                                - zoneLabel
                                - epochMilliseconds
                                - inputDateTime
                              additionalProperties: false
                        required:
                          - dateFormat
                          - timeFormat
                          - timeZone
                          - timestamps
                        additionalProperties: false
                    required:
                      - localization
        '400':
          $ref: '#/components/responses/ApiError'
        '401':
          $ref: '#/components/responses/ApiError'
        '403':
          $ref: '#/components/responses/ApiError'
        '404':
          $ref: '#/components/responses/ApiError'
        '409':
          $ref: '#/components/responses/ApiError'
        '413':
          $ref: '#/components/responses/ApiError'
        '422':
          $ref: '#/components/responses/ApiError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ApiError'
      security:
        - bearerAuth: []
components:
  schemas:
    Response_348:
      type: object
      properties:
        syncs:
          type: array
          items:
            anyOf:
              - $ref: '#/components/schemas/Response_349'
              - $ref: '#/components/schemas/Response_350'
        source:
          $ref: '#/components/schemas/Response_351'
        environments:
          type: array
          items:
            $ref: '#/components/schemas/Response_352'
      required:
        - syncs
        - source
        - environments
    Response_349:
      type: object
      properties:
        environmentId:
          type: string
        syncId:
          type: string
        error:
          type: 'null'
      required:
        - environmentId
        - syncId
        - error
    Response_350:
      type: object
      properties:
        environmentId:
          type: string
        syncId:
          type: 'null'
        error:
          type: string
      required:
        - environmentId
        - syncId
        - error
    Response_351:
      type: object
      properties:
        createdAt:
          type: string
          format: date-time
        id:
          type: string
        provider:
          anyOf:
            - type: string
              const: github
            - type: string
              const: gitlab
        repositoryName:
          type: string
        repositoryOwner:
          type: string
        status:
          anyOf:
            - type: string
              const: active
            - type: string
              const: archived
        updatedAt:
          type: string
          format: date-time
      required:
        - createdAt
        - id
        - provider
        - repositoryName
        - repositoryOwner
        - status
        - updatedAt
    Response_352:
      type: object
  responses:
    ApiError:
      description: Request failed. The error object contains code, message, and requestId.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                required:
                  - code
                  - message
                  - requestId
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  requestId:
                    type: string
    RateLimited:
      description: Request failed. The error object contains code, message, and requestId.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                required:
                  - code
                  - message
                  - requestId
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  requestId:
                    type: string
      headers:
        Retry-After:
          description: Seconds before retrying
          schema:
            type: integer
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Towbar API key

````