# Run a function version by slug and version POST /v1/t/adapters/edge/functions/{slug}/{version} Select code sample ``` const url = 'https://example.com/v1/t/adapters/edge/functions/example/1'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"variables":{"additionalProperty":"example"},"args":{"additionalProperty":"example"}}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ``` curl --request POST \ --url https://example.com/v1/t/adapters/edge/functions/example/1 \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "variables": { "additionalProperty": "example" }, "args": { "additionalProperty": "example" } }' ``` - /v1/t/adapters/edge/functions/{slug}/{version} Same behaviour and response as `POST /api/functions/by-id/{id}`. ## Permission This operation needs the permission [`tenant:scenario_template:manage`](https://docs.aiva.apifonica.com/concepts/roles-and-permissions/#tenant-scenario_template-manage). ## Authorizations - **[bearerAuth](https://docs.aiva.apifonica.com/api/tenant/#bearerauth)** ## Parameters ### Path Parameters **slug** required Function name inside the account. Needs at least one `[A-Za-z0-9_]` character and must not be `by-id`. Other characters are not rejected. string \>= 1 characters <= 100 characters **version** required integer \>= 1 ### Header Parameters **X-Tenant-Sid** string Names the target tenant. By principal: - A tenant-scoped principal may omit it. - A principal with no tenant of its own names one here. Refused when: - A tenant-scoped principal sends a value naming any other tenant. - A principal with no tenant of its own omits it. ## Request Body Media typeapplication/json object **variables** Scenario variables. Read in the code with `storage.get(key)` and passed to the handler as the second argument. object ***key*** additional properties One of: string | null number format: double boolean **args** Passed to the handler as the first argument. Iris sends `{}`. object ***key*** additional properties One of: string | null number format: double boolean ##### Examplegenerated ``` { "variables": { "additionalProperty": "example" }, "args": { "additionalProperty": "example" } } ``` ## Responses ### 200 The run finished. `ok: true` when the handler returned, `ok: false` with `error` when it threw or the sandbox stopped it. Media typeapplication/json object **ok** required boolean **return** required What the handler returned. A string as is, an object or array as JSON, `null` and `undefined` as an empty string, the rest via `String()`. string **variables** required Only the keys the run wrote with `storage.set`, every value as a string (objects as JSON, `null` and `undefined` as an empty string). Iris writes them back into the scenario variables. object ***key*** additional properties string **stdout** required `console.log` lines, cut at 1 KiB with `... [truncated]` string **stderr** required `console.error` lines plus the thrown message, cut at 1 KiB string **error** Present only when `ok` is false string **execution\_time** required Milliseconds, including the bundle download integer ##### Examples Select example ``` { "ok": true, "return": "{\"greeting\":\"Hello, Ann\"}", "variables": { "greeted": "true" }, "stdout": "greeting Ann", "stderr": "", "execution_time": 84 } ``` ``` { "ok": false, "return": "", "variables": {}, "stdout": "", "stderr": "name is required", "error": "name is required", "execution_time": 61 } ``` ``` { "ok": false, "return": "", "variables": {}, "stdout": "", "stderr": "", "error": "Function exceeded timeout", "execution_time": 30004 } ``` ### 400 Domain error. A failed bundle comes as `400` with `err_code: INTERNAL_SERVER_ERROR`. On a run route a bundle that could not be rebuilt is this `400` too. Media typeapplication/json object **ok** required boolean **error** required string **err\_code** required string Allowed values: UNAUTHORIZED FORBIDDEN NOT\_FOUND BAD\_REQUEST INTERNAL\_SERVER\_ERROR VALIDATION\_ERROR ##### Example ``` { "ok": false, "err_code": "UNAUTHORIZED" } ``` ### 401 Unauthorized ### 403 Forbidden ### 404 No version with these keys in the account Media typeapplication/json object **ok** required boolean **error** required string **err\_code** required string Allowed values: UNAUTHORIZED FORBIDDEN NOT\_FOUND BAD\_REQUEST INTERNAL\_SERVER\_ERROR VALIDATION\_ERROR ##### Example ``` { "ok": false, "error": "Function not found", "err_code": "NOT_FOUND" } ``` ### 422 The body, query or path params did not pass the zod schema Media typeapplication/json object **ok** required boolean **error** required string Allowed values: Validation failed **issues** required Zod issues as is Array\ object **code** required string **path** required Array **message** required string ##### Example ``` { "ok": false, "error": "Validation failed" } ``` ### 500 Unexpected error, for example a database or a disk failure. The body has `err_code: INTERNAL_SERVER_ERROR`. Media typeapplication/json object **ok** required boolean **error** required string **err\_code** required string Allowed values: UNAUTHORIZED FORBIDDEN NOT\_FOUND BAD\_REQUEST INTERNAL\_SERVER\_ERROR VALIDATION\_ERROR ##### Example ``` { "ok": false, "err_code": "UNAUTHORIZED" } ``` ### 502 Bad gateway (upstream adapter error)