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

# Add a new User Defined Function



## OpenAPI

````yaml https://dev.enneo.dev/api/mind/docs/open-api post /settings/user-defined-function
openapi: 3.0.0
info:
  version: '1'
  title: enneo.MIND API
  description: This describes the API of enneo Mind, the main ticketing backend
  contact:
    name: enneo GmbH
    email: richard@enneo.ai
  license:
    name: Proprietary software
    url: https://enneo.ai
servers:
  - url: https://demo.enneo.ai/api/mind
    description: Production server, demo client
  - url: https://main.enneo.dev/api/mind
    description: Development main branch
  - url: http://localhost:8005/api/mind
    description: Local development server
security:
  - bearerAuth:
      - api
  - cookieAuth:
      - api
paths:
  /settings/user-defined-function:
    post:
      tags:
        - Settings
      summary: Add a new User Defined Function
      operationId: createUserDefinedFunction
      requestBody:
        description: >-
          The new User Defined Function that should be created. The ID does not
          need to be included in the payload, as it will be generated
          automatically.
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserDefinedFunction'
      responses:
        '200':
          description: User Defined Function added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Indicates if the operation was successful
                    example: true
                  id:
                    type: integer
                    description: The ID of the added User Defined Function
                    example: 12345
        '403':
          description: Unauthorized
        '500':
          description: Internal error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    UserDefinedFunction:
      type: object
      properties:
        id:
          type: integer
          example: 1
        type:
          type: string
          enum:
            - tool
            - udf
        data:
          type: object
          properties:
            udfExecutor:
              type: object
              properties:
                id:
                  type: integer
                  example: 1
                code:
                  type: string
                  example: >-
                    <?php


                    // Load enneo SDK. Input is made available through $in

                    use EnneoSDK\Api;

                    use EnneoSDK\ApiEnneo;

                    require(getenv()['SDK']);


                    function exampleApiCall(string $method, string $api,
                    array|object|string|false $params = false, $attempt = 1):
                    stdClass|array

                    {
                        // load token
                        $token = ApiEnneo::executeUdf('fetchToken', [])->token;

                        // make request
                        $res = Api::call(
                            method: $method,
                            url: sprintf('urlExampleHere', $api),
                            headers: [
                                sprintf('Authorization: Bearer %s', $token),
                                'x-api-key: tokenExampleHere',
                                'Accept: application/json'
                            ],
                            params: $params
                        );

                        return $res;
                    }


                    echo json_encode(exampleApiCall($in->method, $in->api,
                    $in->params));
                type:
                  type: string
                  example: sourceCode
                language:
                  type: string
                  example: php82
                packages:
                  type: string
                  example: ''
                parameters:
                  type: array
                  items:
                    type: object
                    description: Parameter definitions for the executor
                  example: []
        name:
          type: string
          example: exampleApiCall
    Error:
      type: object
      description: Data format of Enneo error messages
      properties:
        error:
          type: string
          example: Contract 121 could not be processed
          description: Readable error message that should be shown to the user
        details:
          type: string
          example: >-
            Uncatched null point exception in testFunction() in
            /app/src/file:212
          description: Not easily readable error message that is for the developer
        txId:
          type: string
          example: c916167c94
          description: >-
            Internal transaction id. Useful for debugging. Corresponds to the
            OpenTelemetry trace ID.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT-based authentication
      x-scopes:
        api: Full access to the API
    cookieAuth:
      type: apiKey
      in: cookie
      name: connect.sid
      description: Cookie-based authentication
      x-scopes:
        api: Full access to the API

````