Skip to content
  • Auto
  • Light
  • Dark
Get Started
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

Create

client.vals.files.create(stringvalID, FileCreateParamsparams, RequestOptionsoptions?): FileCreateResponse { id, links, name, 4 more }
post/v2/vals/{val_id}/files

Create a new file, project val or directory

ParametersExpand Collapse
valID: string
FileCreateParams = Variant0 | Variant1
FileCreateParamsBase { path_, type, branch_id, content }
path_: string

Query param: Path to a file or directory (e.g. 'dir/subdir/file.ts'). Pass in an empty string to represent the root directory.

type: "directory"

Body param:

Accepts one of the following:
"directory"
branch_id?: string

Query param: The specified branch of the resource. Defaults to main if not provided.

formatuuid
content?: unknown

Body param:

Variant0 extends FileCreateParamsBase { path_, type, branch_id, content }
Variant1 extends FileCreateParamsBase { path_, type, branch_id, content }
ReturnsExpand Collapse
FileCreateResponse { id, links, name, 4 more }

A File or Directory's Metadata

id: string

The id of the resource

formatuuid

The URL of this resource on Val Town

formaturi

The URL of this resource's source code as a module

formaturi

The URL of this resource on this API

formaturi

This resource's web endpoint, where it serves a website or API

formaturi
name: string
path: string
type: "directory" | "file" | "interval" | 3 more
Accepts one of the following:
"directory"
"file"
"interval"
"http"
"email"
"script"
updatedAt: string
version: number
import ValTown from "npm:@valtown/sdk";

const client = new ValTown();

const file = await client.vals.files.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
  path: 'path',
  type: 'directory',
});

console.log(file.id);
{
  "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "links": {
    "html": "https://example.com",
    "module": "https://example.com",
    "self": "https://example.com",
    "endpoint": "https://example.com"
  },
  "name": "name",
  "path": "path",
  "type": "directory",
  "updatedAt": "2019-12-27T18:11:19.117Z",
  "version": 0
}
Returns Examples
{
  "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "links": {
    "html": "https://example.com",
    "module": "https://example.com",
    "self": "https://example.com",
    "endpoint": "https://example.com"
  },
  "name": "name",
  "path": "path",
  "type": "directory",
  "updatedAt": "2019-12-27T18:11:19.117Z",
  "version": 0
}