Manage payments, expenses, teams and more with Brex.

Using the Brex API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Brex background job resumable and appear in our dashboard.

  • Use io.runTask() and the official SDK or fetch.

  • Use our HTTP endpoint to subscribe to webhooks

  • Example code using Brex

    Below are some working code examples of how you can use Brex with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

    import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
    import z from "zod";
    // Docs: https://developer.brex.com/openapi/team_api/#tag/Titles
    // API: https://developer.brex.com/openapi/team_api/#operation/createTitle
    const endpointURL = `${process.env.BREX_BASE_URL}/titles`; // Replace with the Other Brex API endpoint
    // Create tokens at https://developer.brex.com/docs/quickstart/#1-generate-your-user-token
    // Scopes: Titles: read, write
    // Create request options
    const requestOptions: RequestInit = {
    method: "POST",
    headers: {
    Authorization: `Bearer ${process.env.BREX_API_KEY}`,
    "Content-Type": "application/json",
    },
    };
    client.defineJob({
    id: "brex-create-title",
    name: "Brex Create Title",
    version: "1.0.0",
    trigger: eventTrigger({
    name: "Brex Create Title",
    schema: z.object({
    // Name of the title. You can see the all titles in the teams section.
    // https://dashboard.brex.com/p/team/titles
    name: z.string(),
    }),
    }),
    run: async (payload, io, ctx) => {
    // Wrap an SDK call in io.runTask so it's resumable and displays in logs
    await io.runTask(
    "Brex Create Title",
    async () => {
    // Make a request to the Brex API using the fetch API
    const response = await fetch(endpointURL, {
    ...requestOptions,
    body: JSON.stringify(payload),
    });
    // Return the response body
    return await response.json();
    },
    // Add metadata to improve how the task displays in the logs
    { name: "Brex Create Title", icon: "brex" }
    );
    },
    });
    ,