Skip to content
Changelog

Report a bug

Call Connected Apps and APIs

Automation code has no fetch. A code stage calls connected apps through Type with ctx. Type adds the credentials and checks access on each call. Your code never sees a credential.

You want toUse
Read with an integration tool, with a typed resultctx.read.call(call, schema)
Change data with an integration tool, with a typed resultctx.write.call(call, schema, { effectKey })
Read from a Custom API connectionctx.read.request(request, schema)
Change data in a Custom API connectionctx.write.request(request, schema, { effectKey })
Call a tool that returns only text, or a sandbox toolctx.tools.call(call, options)
Post in the Spacectx.write.sendMessage(message, { effectKey })

Each connected app has tools. To call one, you need its service, name, input schema, and connection ID (organizationIntegrationId). Use one of these:

  • Ask Type in a thread: “Find the Linear tool that lists issues, with its schema.”
  • Run type-cli integrations list --json, then type-cli integrations tools <service> --integration <organizationIntegrationId> --json.
  • Call ctx.tools.find({ service, organizationIntegrationId }) in code.

Use the exact service, name, and organizationIntegrationId as constants in your code. If the tool has a rawSlug, pass it too. The tool names on this page are examples. Use the names that discovery returns for your connection.

Every tool call returns the standard MCP tool result:

interface ToolResult {
content: Array<{ type: string; text?: string }>;
structuredContent?: unknown; // typed data, if the tool returns it
isError?: boolean; // true when the tool reports an error
}

ctx.tools.call gives you this result as it is. ctx.read.call and ctx.write.call check it and give you only the parsed structuredContent.

This automation reads 20 Linear issues every hour and returns their titles:

import {
automation,
code,
complete,
recurringEventSchema,
} from "@type-dot-com/sdk/automations";
import { err, ok } from "neverthrow";
import { z } from "zod";
const linear = "orgint_example"; // the Linear connection of this Space
const issues = z.object({
issues: z.array(z.looseObject({ id: z.string(), title: z.string() })),
});
export default automation({
output: z.object({ titles: z.array(z.string()) }),
deployment: {
subscriptions: {
hourly: {
title: "List Linear issues",
description: "Read recent Linear issues",
source: {
kind: "recurring",
schedule: { kind: "interval", everySeconds: 3600 },
},
entry: "list",
},
},
},
stages: {
list: code({
input: recurringEventSchema,
transitions: [],
async run({ ctx }) {
const result = await ctx.read.call(
{
service: "linear",
name: "list_issues",
organizationIntegrationId: linear,
arguments: { first: 20 },
},
issues,
);
if (result.isErr()) return err(result.error);
return ok(complete({ titles: result.value.issues.map((issue) => issue.title) }));
},
}),
},
});

ctx.read.call fails with an error result when:

  • the call fails, for example because the automation has no access,
  • the tool returns isError: true,
  • structuredContent is missing or does not match your schema.

Write the schema for the provider data in structuredContent, not for the tool result around it:

  • Describe only the fields that you use.
  • Use z.looseObject(), so new fields from the provider do not fail the run.

These lines go inside a code stage’s run:

const result = await ctx.tools.call({
service: "linear",
name: "get_issue",
organizationIntegrationId: "orgint_example",
arguments: { id: "ENG-123" },
});
if (result.isErr()) return err(result.error);
if (result.value.isError)
return err(new TypeApiError("Linear returned an error", "invalid_response"));
const text = result.value.content.map((item) => item.text ?? "").join("\n");

Check both result.isErr() and result.value.isError. A tool can report an error inside a successful response. TypeApiError comes from @type-dot-com/sdk.

ctx.tools.callWithSchema(call, schema, options?) is a middle form. It returns the full tool result, with structuredContent parsed by your schema.

Use ctx.write.call for tools that change data. It needs an effectKey. In this stage, the input is a Slack message event:

const created = await ctx.write.call(
{
service: "linear",
name: "create_issue",
organizationIntegrationId: "orgint_example",
arguments: { teamId: "TEAM", title: `Deploy failed: ${input.id}` },
},
z.looseObject({ id: z.string() }),
{ effectKey: `linear-issue:${input.id}` },
);
if (created.isErr()) return err(created.error);

Make the effect key stable for the same change. Build it from the event ID or from scheduledAt. An effect key does not stop a write from running two times. If a write has an unknown result, check the destination before you try again. See Write Safely.

To call a tool that returns only text and changes data, use ctx.tools.call(call, { automationEffectKey }).

For a Custom API connection, send HTTP requests with ctx.read.request and ctx.write.request:

const orders = await ctx.read.request(
{ organizationIntegrationId: "orgint_example", method: "GET", path: "/orders", query: { status: "open" } },
z.object({ orders: z.array(z.looseObject({ id: z.string() })) }),
);
if (orders.isErr()) return err(orders.error);
  • path is relative to the connection’s base URL.
  • Type adds the connection’s credentials.
  • The result is the parsed response body.
  • The call fails if the response status is not successful, if Type cut the response because it was too large, or if the body does not match the schema.

Use ctx.read.request for requests that do not change data. Use ctx.write.request with an effectKey for requests that do.

  • The automation acts as the person who created it, with the connections of its Space.
  • Access in a chat thread can differ from access in an automation. A call that works in a thread can still fail in the automation.
  • A tool that can change data needs full access to the connection. With read-only access, Type rejects the call.
  • Type checks access on each call. If someone removes a connection from the Space, later calls fail.
  • In fixtures, Type answers each call with the response that you give in toolResponses or integrationResponses. A test never calls the app.
ItemLimit
Requests to Type from one code stage128
Requests in progress at the same time8
Response2 MiB. Ask for smaller pages if a response is larger.
Request body1 MiB
One call to a sandbox or type-api tool170 seconds

See Limits.