Skip to content

My resources

When using the Val Town API, some of the most common functions operate on things that you own. For these kinds of operations, there are the “me” routes.

GET /v1/me

Get profile information for the current user

Example
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let getMe = fetchJSON(`https://api.val.town/v1/me`, {
headers: {
Authorization: `Bearer ${Deno.env.get("valtown")}`,
},
});

GET /v1/me/runs

Example
import { runs } from "https://esm.town/v/stevekrouse/runs?v=17";
export let getRuns = runs({
token: Deno.env.get("valtown"),
error: false,
limit: 10,
offset: 0,
// last 30 minutes
since: new Date(Number(new Date()) - 1800000),
until: new Date(),
});

GET /v1/me/likes

Get vals liked by the current user

Example
import { likes } from "https://esm.town/v/neverstew/likes";
export let getLikes = likes({
token: Deno.env.get("valtown"),
limit: 10,
offset: 0,
});

GET /v1/me/comments

Get comments related to current user, either given or received

Example
import { comments } from "https://esm.town/v/neverstew/comments";
export let getComments = comments({
token: Deno.env.get("valtown"),
relationship: "any",
limit: 10,
offset: 0,
// last 30 minutes
since: new Date(Number(new Date()) - 1800000),
until: new Date(),
});

Get /v1/me/references

Returns vals that depend on any of the user’s vals

Example
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=42";
export const references = await fetchJSON(
"https://api.val.town/v1/me/references",
{
headers: { Authorization: `Bearer ${Deno.env.get("valtown")}` },
}
);