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

# Generate grant code

> Generate a new grant code for a specific action. The grant code can be used to perform the specified action from the client.



## OpenAPI

````yaml /api/grant-codes/openapi.yaml post /grant-codes/generate
openapi: 3.1.0
info:
  title: Unified CDN API | Grant codes
  description: Interact with grant codes in the Unified CDN system.
  version: 0.1.0
servers:
  - url: https://{Unified_CDN_domain}/api
    description: Production server where your Unified CDN is hosted.
    variables:
      Unified_CDN_domain:
        default: api.example.com
        description: >-
          The domain where your Unified CDN is hosted. Change this to your
          custom domain if you have one.
security: []
paths:
  /grant-codes/generate:
    post:
      summary: Generate grant code
      description: >-
        Generate a new grant code for a specific action. The grant code can be
        used to perform the specified action from the client.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/UploadFilesGrantCodeRequest'
                - $ref: '#/components/schemas/DeleteFilesGrantCodeRequest'
              discriminator:
                propertyName: action
                mapping:
                  UPLOAD_FILES: '#/components/schemas/UploadFilesGrantCodeRequest'
                  DELETE_FILES: '#/components/schemas/DeleteFilesGrantCodeRequest'
      responses:
        '200':
          description: Grant code generated successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: The generated grant code.
        '400':
          description: Bad request due to invalid configuration
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missingFields:
                  summary: Missing fields
                  value:
                    error: InvalidConfigurationError
                    message: Missing action or data in request body.
                invalidAction:
                  summary: Invalid action
                  value:
                    error: InvalidConfigurationError
                    message: 'Invalid action in request body. Must be one of: [...]'
        '401':
          $ref: '#/components/responses/UnauthorisedError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    UploadFilesGrantCodeRequest:
      title: Upload files
      allOf:
        - $ref: '#/components/schemas/GrantCodeRequest'
        - type: object
          required:
            - action
            - data
          properties:
            action:
              type: string
              const: UPLOAD_FILES
              default: UPLOAD_FILES
            data:
              type: object
              required:
                - fileCount
              properties:
                fileCount:
                  type: integer
                  description: >-
                    Number of files the code is allowed to upload. The code must
                    upload exactly this number, or the request will fail.
                maximumFileSize:
                  description: >-
                    Maximum size in bytes for each file the code is allowed to
                    upload. Defaults to unlimited, or the application's limit.
                  type: integer
                maximumTotalSize:
                  description: >-
                    Maximum total size in bytes for all files the code is
                    allowed to upload. Defaults to unlimited, or the
                    application's limit.
                  type: integer
                allowedFileTypes:
                  type: array
                  description: >-
                    Array of allowed MIME types for the files the code is
                    allowed to upload. If not specified, all file types are
                    allowed.
                  items:
                    type: string
    DeleteFilesGrantCodeRequest:
      title: Delete files
      allOf:
        - $ref: '#/components/schemas/GrantCodeRequest'
        - type: object
          required:
            - action
            - data
          properties:
            action:
              type: string
              const: DELETE_FILES
              default: DELETE_FILES
            data:
              type: object
              required:
                - fileIds
              properties:
                fileIds:
                  type: array
                  description: Array of file IDs you want the code to be allowed to delete.
                  items:
                    type: string
    Error:
      type: object
      required:
        - code
        - message
      properties:
        error:
          type: string
        message:
          type: string
    GrantCodeRequest:
      type: object
      required:
        - action
      properties:
        action:
          type: string
          description: >-
            Action which the grant code is allowed to execute. [Do not change
            this!]
        expiresIn:
          type: integer
          minimum: 1
          description: >-
            Duration in seconds for which the grant code is valid. Defaults to
            300 seconds (5 minutes).
  responses:
    UnauthorisedError:
      description: The request lacks valid authentication credentials.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            unauthorised:
              value:
                error: UnauthorisedError
                message: You are unauthorised to perform this action.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Enter your API key using the format `Bearer <your-api-key>`.

````

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