Back to APIs

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.

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import z from "zod";
3
4
// Docs: https://developer.brex.com/openapi/team_api/#tag/Titles
5
// API: https://developer.brex.com/openapi/team_api/#operation/createTitle
6
const endpointURL = `${process.env.BREX_BASE_URL}/titles`; // Replace with the Other Brex API endpoint
7
8
// Create tokens at https://developer.brex.com/docs/quickstart/#1-generate-your-user-token
9
// Scopes: Titles: read, write
10
// Create request options
11
const requestOptions: RequestInit = {
12
method: "POST",
13
headers: {
14
Authorization: `Bearer ${process.env.BREX_API_KEY}`,
15
"Content-Type": "application/json",
16
},
17
};
18
19
//<> ### This is a title
20
//<> **This is a bold comment 1 ** and `this is code`
21
client.defineJob({
22
id: "brex-create-title",
23
name: "Brex Create Title",
24
version: "1.0.0",
25
trigger: eventTrigger({
26
name: "Brex Create Title",
27
schema: z.object({
28
// Name of the title. You can see the all titles in the teams section.
29
// https://dashboard.brex.com/p/team/titles
30
name: z.string(),
31
}),
32
}),
33
//</>
34
run: async (payload, io, ctx) => {
35
// Wrap an SDK call in io.runTask so it's resumable and displays in logs
36
await io.runTask(
37
"Brex Create Title",
38
async () => {
39
// Make a request to the Brex API using the fetch API
40
const response = await fetch(endpointURL, {
41
...requestOptions,
42
body: JSON.stringify(payload),
43
});
44
45
// Return the response body
46
return await response.json();
47
},
48
49
//<> This is comment 2
50
// Add metadata to improve how the task displays in the logs
51
{ name: "Brex Create Title", icon: "brex" }
52
//</>
53
);
54
},
55
});