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

# Grant or replace Factorize permissions for an existing VM

> Supply a preset ID or an explicit scope list. Factorize saves the resolved scope snapshot and rejects the entire request if any scope exceeds the caller's effective access. Use one requestKey per initial enrollment and reuse it for a retry. Supply the current revision when editing an existing grant.

Requires the vms:edit scope.

Accepts a scoped bearer token or interactive owner session.



## OpenAPI

````yaml /openapi.yaml post /api/v1/vms/grants
openapi: 3.1.0
info:
  title: Factorize API
  version: 1.0.0
  description: >-
    Versioned Factorize REST API. See the hosted docs for examples and OAuth
    discovery.
  x-dashboard-auth: >-
    Access-token and authorized-client management require an interactive owner
    session; all other operations accept a suitably scoped bearer token or owner
    session.
servers:
  - url: https://app.factorize.sh
security:
  - bearerAuth: []
paths:
  /api/v1/vms/grants:
    post:
      tags:
        - vms
      summary: Grant or replace Factorize permissions for an existing VM
      description: >-
        Supply a preset ID or an explicit scope list. Factorize saves the
        resolved scope snapshot and rejects the entire request if any scope
        exceeds the caller's effective access. Use one requestKey per initial
        enrollment and reuse it for a retry. Supply the current revision when
        editing an existing grant.


        Requires the vms:edit scope.


        Accepts a scoped bearer token or interactive owner session.
      operationId: post_api_v1_vms_grants
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                target:
                  oneOf:
                    - type: object
                      properties:
                        kind:
                          type: string
                          const: machine
                        providerId:
                          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)$
                        vm:
                          type: string
                          pattern: ^[a-zA-Z0-9-]{1,64}$
                        app:
                          type: string
                          pattern: ^[a-z0-9-]{1,64}$
                        requestKey:
                          type: string
                          minLength: 1
                          maxLength: 200
                      required:
                        - kind
                        - providerId
                        - vm
                        - requestKey
                      additionalProperties: false
                    - type: object
                      properties:
                        kind:
                          type: string
                          const: existing
                        grantId:
                          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)$
                        expectedRevision:
                          type: integer
                          exclusiveMinimum: 0
                          maximum: 9007199254740991
                      required:
                        - kind
                        - grantId
                        - expectedRevision
                      additionalProperties: false
                permissions:
                  type: object
                  properties:
                    scopes:
                      maxItems: 100
                      type: array
                      items:
                        type: string
                        minLength: 1
                        maxLength: 200
                  required:
                    - scopes
                  additionalProperties: false
              required:
                - target
                - permissions
              additionalProperties: false
      responses:
        '200':
          description: VM grant and guest authentication metadata
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    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)$
                  providerId:
                    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)$
                  provider:
                    type: string
                    enum:
                      - exe.dev
                      - fly.io
                  vm:
                    type: string
                  app:
                    type:
                      - string
                      - 'null'
                  scopes:
                    type: array
                    items:
                      type: string
                  revision:
                    type: integer
                    exclusiveMinimum: 0
                    maximum: 9007199254740991
                  createdAt:
                    type: string
                    format: date-time
                    pattern: >-
                      ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
                  updatedAt:
                    type: string
                    format: date-time
                    pattern: >-
                      ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
                  authentication:
                    type: object
                    properties:
                      audience:
                        type: string
                      guestKeyPath:
                        type: string
                    required:
                      - audience
                      - guestKeyPath
                    additionalProperties: false
                required:
                  - id
                  - providerId
                  - provider
                  - vm
                  - app
                  - scopes
                  - revision
                  - createdAt
                  - updatedAt
                  - authentication
                additionalProperties: false
        '400':
          $ref: '#/components/responses/Error400'
        '401':
          $ref: '#/components/responses/Error401'
        '403':
          $ref: '#/components/responses/Error403'
        '404':
          $ref: '#/components/responses/Error404'
        '409':
          $ref: '#/components/responses/Error409'
        '415':
          $ref: '#/components/responses/Error415'
        '429':
          $ref: '#/components/responses/Error429'
        '500':
          $ref: '#/components/responses/Error500'
        '503':
          $ref: '#/components/responses/Error503'
      security:
        - bearerAuth: []
        - cookieAuth: []
components:
  responses:
    Error400:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error401:
      description: Invalid or revoked credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error403:
      description: Missing scope or required owner session
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error404:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error409:
      description: Operation conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error415:
      description: Unsupported media type; use application/json
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error429:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error500:
      description: Internal error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Error503:
      description: Service unavailable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: OAuth2
    cookieAuth:
      type: apiKey
      in: cookie
      name: factorize_session

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.