world.hooks

Look up workflow hooks by ID or token for webhook resume flows and metadata inspection.

The world.hooks interface provides access to workflow hook data. Hooks are pause points in workflows that wait for external input. Use this interface to look up hooks by ID or token, inspect metadata, and build admin UIs for pending approvals.

Import

import { getWorld } from "workflow/runtime";

const world = getWorld();
const hooks = world.hooks; 

Methods

get()

Retrieve a hook by its ID.

const hook = await world.hooks.get(hookId); 

Parameters:

ParameterTypeDescription
hookIdstringThe hook ID
paramsobjectOptional parameters

Returns: Hook

getByToken()

Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.

const hook = await world.hooks.getByToken(token); 

Parameters:

ParameterTypeDescription
tokenstringThe hook token
paramsobjectOptional parameters

Returns: Hook

list()

List hooks with cursor pagination.

const result = await world.hooks.list({ 
  pagination: { cursor },
}); 

Parameters:

ParameterTypeDescription
params.pagination.cursorstringCursor for the next page

Returns: { data: Hook[], cursor?: string }

Types

Hook

FieldTypeDescription
runIdstringParent workflow run ID
hookIdstringUnique hook identifier
tokenstringHook token for resuming
ownerIdstringOwner (team/user) ID
projectIdstringProject ID
environmentstringDeployment environment
metadataobjectCustom metadata attached to the hook
isWebhookbooleanWhether this is a webhook-style hook

Examples

Look Up Hook by ID

import { getWorld } from "workflow/runtime";

export async function GET(req: Request) {
  const url = new URL(req.url);
  const hookId = url.searchParams.get("hookId");

  if (!hookId) {
    return Response.json({ error: "hookId required" }, { status: 400 });
  }

  const world = getWorld();
  const hook = await world.hooks.get(hookId); 

  return Response.json({
    hookId: hook.hookId,
    runId: hook.runId,
    token: hook.token,
    metadata: hook.metadata,
  });
}

Look Up Hook by Token for Webhook Resume

When you receive a webhook callback with a token, look up the hook to inspect metadata before resuming:

import { getWorld } from "workflow/runtime";

export async function POST(req: Request) {
  const { token } = await req.json();

  const world = getWorld();
  const hook = await world.hooks.getByToken(token); 

  // Inspect hook metadata before deciding to resume
  console.log(hook.runId, hook.metadata); 

  return Response.json({
    runId: hook.runId,
    hookId: hook.hookId,
    metadata: hook.metadata,
  });
}

List All Hooks for Pending Approvals Dashboard

import { getWorld } from "workflow/runtime";

export async function GET(req: Request) {
  const url = new URL(req.url);
  const cursor = url.searchParams.get("cursor") ?? undefined;

  const world = getWorld();
  const hooks = await world.hooks.list({ 
    pagination: { cursor },
  }); 

  return Response.json(hooks);
}