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

# Create a folder policy for a connection

> Create or update a folder policy for a specific connection.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/hyperspell.yaml post /connections/{connection_id}/folder-policies
openapi: 3.1.0
info:
  title: Hyperspell API
  summary: >-
    Hyperspell is the memory layer for AI apps and agents. Through the API, you
    can add memories, connect data sources to index them in real-time, and
    search memories with our natural language query engine.
  termsOfService: https://hyperspell.com/blog/tos
  contact:
    name: Hyperspell
    url: https://hyperspell.com/
    email: hello@hyperspell.com
  version: 0.32.1
servers:
  - url: https://api.hyperspell.com
    description: Production
security:
  - APIKey: []
    AsUser: []
paths:
  /connections/{connection_id}/folder-policies:
    post:
      tags:
        - Folder Policies
      summary: Create a folder policy for a connection
      description: Create or update a folder policy for a specific connection.
      operationId: >-
        create_connection_policy_connections__connection_id__folder_policies_post
      parameters:
        - name: connection_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Connection Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateFolderPolicyRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FolderPolicyResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKey: []
        - AsUser: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Hyperspell from '@hyperspell/hyperspell';


            const client = new Hyperspell({
              apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.folders.setPolicies('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
              provider_folder_id: 'provider_folder_id',
              sync_mode: 'sync',
            });


            console.log(response.id);
        - lang: Python
          source: |-
            import os
            from hyperspell import Hyperspell

            client = Hyperspell(
                api_key=os.environ.get("HYPERSPELL_API_KEY"),  # This is the default and can be omitted
            )
            response = client.folders.set_policies(
                connection_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                provider_folder_id="provider_folder_id",
                sync_mode="sync",
            )
            print(response.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/hyperspell/hyperspell-go\"\n\t\"github.com/hyperspell/hyperspell-go/option\"\n)\n\nfunc main() {\n\tclient := hyperspell.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Folders.SetPolicies(\n\t\tcontext.TODO(),\n\t\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\t\thyperspell.FolderSetPoliciesParams{\n\t\t\tProviderFolderID: \"provider_folder_id\",\n\t\t\tSyncMode:         hyperspell.FolderSetPoliciesParamsSyncModeSync,\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.ID)\n}\n"
        - lang: CLI
          source: |-
            hyperspell folders set-policies \
              --api-key 'My API Key' \
              --connection-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e \
              --provider-folder-id provider_folder_id \
              --sync-mode sync
components:
  schemas:
    CreateFolderPolicyRequest:
      properties:
        provider_folder_id:
          type: string
          title: Provider Folder Id
          description: Folder ID from the source provider
        folder_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Name
          description: Display name of the folder
        folder_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Path
          description: Display path of the folder
        parent_folder_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Parent Folder Id
          description: Parent folder's provider ID for inheritance resolution
        sync_mode:
          $ref: '#/components/schemas/SyncMode'
          description: Sync mode for this folder
      type: object
      required:
        - provider_folder_id
        - sync_mode
      title: CreateFolderPolicyRequest
    FolderPolicyResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: Unique policy ID
        provider_folder_id:
          type: string
          title: Provider Folder Id
          description: Folder ID from the source provider
        folder_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Name
          description: Display name of the folder
        folder_path:
          anyOf:
            - type: string
            - type: 'null'
          title: Folder Path
          description: Display path of the folder
        parent_folder_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Parent Folder Id
          description: Parent folder's provider ID
        sync_mode:
          $ref: '#/components/schemas/SyncMode'
          description: Sync mode for this folder
        connection_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Connection Id
          description: Connection ID (null for integration defaults)
      type: object
      required:
        - id
        - provider_folder_id
        - sync_mode
      title: FolderPolicyResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SyncMode:
      type: string
      enum:
        - sync
        - skip
        - manual
      title: SyncMode
    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:
    APIKey:
      type: http
      description: >-
        API Key or JWT User Token. If using an API Key, set the X-As-User header
        to act as a specific user. A JWT User Token is always scoped to a
        specific user.
      scheme: bearer
      bearerFormat: Bearer <token>
    AsUser:
      type: apiKey
      description: >-
        Optionally set this header to act as a specific user when using an API
        Key, equivalent to first exchanging the API Key for a User Token
      in: header
      name: X-As-User

````