# Create a function version POST /v1/t/adapters/edge/functions Select code sample ``` const url = 'https://example.com/v1/t/adapters/edge/functions'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"slug":"example","code":"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 \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "slug": "example", "code": "example" }' ``` - /v1/t/adapters/edge/functions Validates the code, bundles it and stores a new version of `slug`. If the latest version of `slug` has exactly the same `code`, nothing is bundled: the existing version is returned. Otherwise the version is the latest one plus 1 (the first one is 1) and it becomes the latest. Validation runs inside the request and can take seconds: forbidden lexemes, `deno check` against the runtime globals, ESLint. Bundling (`deno install` + `deno bundle`) runs inside the request too. ## 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 ### 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 Bodyrequired Media typeapplication/json object **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 **code** required TypeScript or JavaScript module with a default export (or a `handler` export). Rejected with `422` when it has a forbidden lexeme, fails `deno check` against the runtime globals, or fails ESLint. See FLOW\.md for the lists. string \>= 1 characters <= 10000 characters ##### Examplegenerated ``` { "slug": "example", "code": "example" } ``` ## Responses ### 200 Version created, or the latest one reused Media typeapplication/json object **ok** required boolean **id** required string format: uuid **version** required integer \>= 1 **storage\_reads** required Keys found in the code as string literals of `storage.get` / `storage.unpack` (reads) or `storage.set` (writes). Keys built at runtime are not found. Array\ **storage\_writes** required Keys found in the code as string literals of `storage.get` / `storage.unpack` (reads) or `storage.set` (writes). Keys built at runtime are not found. Array\ ##### Example ``` { "ok": true } ``` ### 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 ### 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)