Execute custom JavaScript in Dynatrace with the Function Executor API, sending source code, payload, and SDK major versions to run a function.
| POST | SaaS | https://{your-environment-id}.apps.dynatrace.com/v1/executions |
You submit sourceCode, payload, and sdkMajorVersions in the request body to execute a given function in the Dynatrace JavaScript runtime. The operation returns 200 OK when the function runs successfully.
To execute this request, you need a platform token or OAuth access token with app-engine:functions:run scope. To learn how to obtain and use it, see Tokens and authentication.
| Parameter | Type | Description | In | Required |
|---|---|---|---|---|
| body | Function | One off code execution request. | body | Required |
FunctionExecutionRequest objectOne off code execution request.
| Element | Type | Description | Required |
|---|---|---|---|
| sourceCode | string | source code that gets executed | Required |
| payload | string | optional argument for the function defined in sourceCode | Optional |
| sdkMajorVersions | object | Optional map of SDK package names to their major version numbers. Non-mentioned packages fall back to default versions. Max key length is 300 characters, max value length is 100 characters. | Optional |
This is a model of the request body, showing the possible elements. It has to be adjusted for usage in an actual request.
{"sourceCode": "export default async function ({addThis}) { return 1 + addThis }","payload": "{\"addThis\":2}","sdkMajorVersions": {"@dynatrace-sdk/adhoc-utils": "1","@dynatrace-sdk/client-classic-environment-v2": "5"}}
| Code | Type | Description |
|---|---|---|
| 200 | Adhoc | OK |
| 400 | Error | Bad Request |
| 540 | Adhoc | JavaScript Error occurred |
| 541 | Adhoc | Runtime Error occurred |
AdhocSuccessResponse object| Element | Type | Description |
|---|---|---|
| logs | string | - |
| result | Json | - |
| packageVersions | object | Map of SDK package names to their resolved versions used during execution |
JsonNode objectErrorEnvelope objectError response for all 4xx and 5xx errors.
| Element | Type | Description |
|---|---|---|
| error | Error | Contains information for 4xx and 5xx errors. |
Error objectContains information for 4xx and 5xx errors.
| Element | Type | Description |
|---|---|---|
| code | integer | The HTTP status code |
| message | string | The error message |
| details | Error | Contains details for 4xx and 5xx errors. |
| help | string | Additional information related to the error |
| retryAfterSeconds | integer | Seconds to wait until the next retry |
ErrorDetails objectContains details for 4xx and 5xx errors.
| Element | Type | Description |
|---|---|---|
| errorRef | string | Generated unique value for 5xx errors. |
| traceId | string | OpenTelemetry trace id of the trace where error occurs. |
| errorCode | string | An optional error code that contains more detailed error information than the HTTP response code alone. |
| errorCodeProperties | object | Additional properties related to the provided error code |
| constraintViolations | Constraint | A list of constraint violations |
ConstraintViolation objectContains information about a constraint violation caused by invalid input.
| Element | Type | Description |
|---|---|---|
| path | string | The path of the property that caused the constraint violation |
| message | string | The error message |
| errorCode | string | An optional error code that contains more detailed error information. |
| errorCodeProperties | object | Additional properties related to the provided error code. |
{"logs": "string","result": {},"packageVersions": {}}
{"error": {"code": 1,"message": "string","details": {"errorRef": "string","traceId": "string","errorCode": "string","errorCodeProperties": {},"constraintViolations": [{"path": "string","message": "string","errorCode": "string","errorCodeProperties": {}}]},"help": "string","retryAfterSeconds": 1}}