Creates a referral
One script reply has been approved by the moderators Verified

This creates new referrals. The response will contain an identifier and a unique personalized link to an application flow. Many fields are optional and when they're provided they'll prefill the application flow for Brex. You should handle and store these references securely as they contain sensitive information about the referral.

Created by hugo697 169 days ago
Submitted by hugo697 Bun
Verified 169 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * Creates a referral
7
 * This creates new referrals. The response will contain an identifier and a unique personalized link to an application flow. Many fields are optional and when they're provided they'll prefill the application flow for Brex.  You should handle and store these references securely as they contain sensitive information about the referral.
8
 */
9
export async function main(
10
  auth: Brex,
11
  body: {
12
    referral_code: string;
13
    applicant: { last_name: string; first_name: string; email: string };
14
    business?: {
15
      legal_name?: string;
16
      incorporation_type?:
17
        | ("C_CORP" & {})
18
        | ("S_CORP" & {})
19
        | ("B_CORP" & {})
20
        | ("LLC" & {})
21
        | ("LLP" & {})
22
        | ("SOLE_PROP" & {})
23
        | ("ORG_501C3" & {})
24
        | ("LP" & {});
25
      employer_identification_number?: string;
26
      website_url?: string;
27
      activity_description?: string;
28
      address?: {
29
        line1?: string;
30
        line2?: string;
31
        city?: string;
32
        state?: string;
33
        country?: string;
34
        postal_code?: string;
35
        phone_number?: string;
36
      } & {};
37
      beneficial_owners?: {
38
        legal_name: string;
39
        company_relationship?:
40
          | ("FOUNDER" & {})
41
          | ("EXECUTIVE" & {})
42
          | ("SENIOR_LEADERSHIP" & {})
43
          | ("OTHER" & {});
44
        date_of_birth?: string;
45
        identity_document?: {
46
          country: string;
47
          type: "SSN" | "PASSPORT";
48
          number: string;
49
        } & {};
50
        address?: {
51
          line1?: string;
52
          line2?: string;
53
          city?: string;
54
          state?: string;
55
          country?: string;
56
          postal_code?: string;
57
          phone_number?: string;
58
        } & {};
59
        prong: "OWNERSHIP" | "CONTROL" | "BOTH";
60
      }[];
61
      alternate_address?: {
62
        line1?: string;
63
        line2?: string;
64
        city?: string;
65
        state?: string;
66
        country?: string;
67
        postal_code?: string;
68
        phone_number?: string;
69
      } & {};
70
    } & {};
71
    contact_preference?: ("NO_OUTBOUND" & {}) | ("EMAIL_OUTBOUND" & {});
72
  },
73
) {
74
  const url = new URL(`https://platform.brexapis.com/v1/referrals`);
75

76
  const response = await fetch(url, {
77
    method: "POST",
78
    headers: {
79
      "Content-Type": "application/json",
80
      Authorization: "Bearer " + auth.token,
81
    },
82
    body: JSON.stringify(body),
83
  });
84
  if (!response.ok) {
85
    const text = await response.text();
86
    throw new Error(`${response.status} ${text}`);
87
  }
88
  return await response.json();
89
}
90