> For the complete documentation index, see [llms.txt](https://docs.ninox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ninox.com/ninox-api/api-reference/api-endpoints/global-functions.md).

# Global Functions

## List global function scripts

> Lists the module's global function scripts, in the name order they compile in

```json
{"openapi":"3.0.0","info":{"title":"Ninox Public API","version":"1.0.0"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"API Key","description":"Enter your Workspace API key. \n\n API keys can be generated and managed within the **Workspace Integration** settings in the Ninox app.","in":"header","name":"Authorization","type":"http"}},"schemas":{"ModuleScriptsResponse":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string","description":"Script of function definitions, callable from every script of the module"},"id":{"type":"string","description":"Global function script id"},"moduleName":{"type":"string","description":"Module name"},"name":{"type":"string","description":"Global function script name, scripts compile in name order"}},"required":["code","id","moduleName","name"]},"description":"Global function scripts of the module, in name order"}},"required":["data"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}}},"required":["error"]}}},"paths":{"/api/v1/workspace/{workspaceId}/modules/{moduleName}/functions":{"get":{"operationId":"ModuleScriptsV1Controller_listModuleScripts","summary":"List global function scripts","description":"Lists the module's global function scripts, in the name order they compile in","parameters":[{"name":"moduleName","required":true,"in":"path","description":"Module name","schema":{"minLength":1,"maxLength":100,"pattern":"^[a-z0-9_]+$","type":"string"}},{"name":"workspaceId","required":true,"in":"path","description":"Workspace ID","schema":{"minLength":12,"maxLength":12,"pattern":"^[a-z0-9]+$","type":"string"}}],"responses":{"200":{"description":"Scripts retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModuleScriptsResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Workspace or module not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Global functions"]}}}}
```

## Create a global function script

> Creates a script of global function definitions, callable from every script of the module. The code may only define functions and is compiled with the functions of the scripts before it by name. Needs schema:write plus records:write.

```json
{"openapi":"3.0.0","info":{"title":"Ninox Public API","version":"1.0.0"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"API Key","description":"Enter your Workspace API key. \n\n API keys can be generated and managed within the **Workspace Integration** settings in the Ninox app.","in":"header","name":"Authorization","type":"http"}},"schemas":{"CreateModuleScriptBody":{"type":"object","properties":{"code":{"type":"string","description":"Function definitions only, callable from every script of the module. Needs schema:write plus records:write"},"name":{"type":"string","minLength":1,"maxLength":100,"description":"Script name, scripts compile in name order"}},"required":["code","name"],"additionalProperties":false},"ModuleScriptResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"code":{"type":"string","description":"Script of function definitions, callable from every script of the module"},"id":{"type":"string","description":"Global function script id"},"moduleName":{"type":"string","description":"Module name"},"name":{"type":"string","description":"Global function script name, scripts compile in name order"}},"description":"Global function script"}},"required":["data"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}}},"required":["error"]}}},"paths":{"/api/v1/workspace/{workspaceId}/modules/{moduleName}/functions":{"post":{"operationId":"ModuleScriptsV1Controller_createModuleScript","summary":"Create a global function script","description":"Creates a script of global function definitions, callable from every script of the module. The code may only define functions and is compiled with the functions of the scripts before it by name. Needs schema:write plus records:write.","parameters":[{"name":"moduleName","required":true,"in":"path","description":"Module name","schema":{"minLength":1,"maxLength":100,"pattern":"^[a-z0-9_]+$","type":"string"}},{"name":"workspaceId","required":true,"in":"path","description":"Workspace ID","schema":{"minLength":12,"maxLength":12,"pattern":"^[a-z0-9]+$","type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateModuleScriptBody"}}}},"responses":{"201":{"description":"Script created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModuleScriptResponse"}}}},"400":{"description":"Code does not compile or defines more than functions","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Missing records:write","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Workspace or module not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"A script with that name already exists","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Global functions"]}}}}
```

## Get a global function script

> Retrieves a global function script by name

```json
{"openapi":"3.0.0","info":{"title":"Ninox Public API","version":"1.0.0"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"API Key","description":"Enter your Workspace API key. \n\n API keys can be generated and managed within the **Workspace Integration** settings in the Ninox app.","in":"header","name":"Authorization","type":"http"}},"schemas":{"ModuleScriptResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"code":{"type":"string","description":"Script of function definitions, callable from every script of the module"},"id":{"type":"string","description":"Global function script id"},"moduleName":{"type":"string","description":"Module name"},"name":{"type":"string","description":"Global function script name, scripts compile in name order"}},"description":"Global function script"}},"required":["data"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}}},"required":["error"]}}},"paths":{"/api/v1/workspace/{workspaceId}/modules/{moduleName}/functions/{scriptName}":{"get":{"operationId":"ModuleScriptsV1Controller_getModuleScript","summary":"Get a global function script","description":"Retrieves a global function script by name","parameters":[{"name":"moduleName","required":true,"in":"path","description":"Module name","schema":{"minLength":1,"maxLength":100,"pattern":"^[a-z0-9_]+$","type":"string"}},{"name":"workspaceId","required":true,"in":"path","description":"Workspace ID","schema":{"minLength":12,"maxLength":12,"pattern":"^[a-z0-9]+$","type":"string"}},{"name":"scriptName","required":true,"in":"path","description":"Global function script name","schema":{"minLength":1,"maxLength":100,"type":"string"}}],"responses":{"200":{"description":"Script retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModuleScriptResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Workspace, module or script not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Global functions"]}}}}
```

## Delete a global function script

> Deletes a global function script. Scripts after it that call its functions are not checked again. Needs records:write

```json
{"openapi":"3.0.0","info":{"title":"Ninox Public API","version":"1.0.0"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"API Key","description":"Enter your Workspace API key. \n\n API keys can be generated and managed within the **Workspace Integration** settings in the Ninox app.","in":"header","name":"Authorization","type":"http"}},"schemas":{"DeleteModuleScriptResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"id":{"type":"string","description":"Deleted script id"}}}},"required":["data"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}}},"required":["error"]}}},"paths":{"/api/v1/workspace/{workspaceId}/modules/{moduleName}/functions/{scriptName}":{"delete":{"operationId":"ModuleScriptsV1Controller_deleteModuleScript","summary":"Delete a global function script","description":"Deletes a global function script. Scripts after it that call its functions are not checked again. Needs records:write","parameters":[{"name":"moduleName","required":true,"in":"path","description":"Module name","schema":{"minLength":1,"maxLength":100,"pattern":"^[a-z0-9_]+$","type":"string"}},{"name":"workspaceId","required":true,"in":"path","description":"Workspace ID","schema":{"minLength":12,"maxLength":12,"pattern":"^[a-z0-9]+$","type":"string"}},{"name":"scriptName","required":true,"in":"path","description":"Global function script name","schema":{"minLength":1,"maxLength":100,"type":"string"}}],"responses":{"200":{"description":"Script deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteModuleScriptResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Missing records:write","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Workspace, module or script not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Global functions"]}}}}
```

## Update a global function script

> Updates or renames a global function script. The result is compiled again with the functions of the scripts before it by name. Scripts after it that call its functions are not checked again. Needs schema:write plus records:write.

```json
{"openapi":"3.0.0","info":{"title":"Ninox Public API","version":"1.0.0"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"API Key","description":"Enter your Workspace API key. \n\n API keys can be generated and managed within the **Workspace Integration** settings in the Ninox app.","in":"header","name":"Authorization","type":"http"}},"schemas":{"UpdateModuleScriptBody":{"type":"object","properties":{"code":{"type":"string","description":"Function definitions only, callable from every script of the module. Needs schema:write plus records:write"},"name":{"type":"string","minLength":1,"maxLength":100,"description":"Script name, scripts compile in name order"}},"additionalProperties":false},"ModuleScriptResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"code":{"type":"string","description":"Script of function definitions, callable from every script of the module"},"id":{"type":"string","description":"Global function script id"},"moduleName":{"type":"string","description":"Module name"},"name":{"type":"string","description":"Global function script name, scripts compile in name order"}},"description":"Global function script"}},"required":["data"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}}},"required":["error"]}}},"paths":{"/api/v1/workspace/{workspaceId}/modules/{moduleName}/functions/{scriptName}":{"patch":{"operationId":"ModuleScriptsV1Controller_updateModuleScript","summary":"Update a global function script","description":"Updates or renames a global function script. The result is compiled again with the functions of the scripts before it by name. Scripts after it that call its functions are not checked again. Needs schema:write plus records:write.","parameters":[{"name":"moduleName","required":true,"in":"path","description":"Module name","schema":{"minLength":1,"maxLength":100,"pattern":"^[a-z0-9_]+$","type":"string"}},{"name":"workspaceId","required":true,"in":"path","description":"Workspace ID","schema":{"minLength":12,"maxLength":12,"pattern":"^[a-z0-9]+$","type":"string"}},{"name":"scriptName","required":true,"in":"path","description":"Global function script name","schema":{"minLength":1,"maxLength":100,"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateModuleScriptBody"}}}},"responses":{"200":{"description":"Script updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModuleScriptResponse"}}}},"400":{"description":"Code does not compile or defines more than functions","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Missing records:write","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Workspace, module or script not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"A script with the new name already exists","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Global functions"]}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ninox.com/ninox-api/api-reference/api-endpoints/global-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
