Create a new document upload
One script reply has been approved by the moderators Verified

The uri will be a presigned S3 URL allowing you to upload the referral doc securely.

Created by hugo697 170 days ago
Submitted by hugo697 Bun
Verified 170 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * Create a new document upload
7
 * 
8
The `uri` will be a presigned S3 URL allowing you to upload the referral doc securely.
9
 */
10
export async function main(
11
  auth: Brex,
12
  id: string,
13
  body: {
14
    type:
15
      | "ARTICLES_OF_INCORPORATION"
16
      | "IRS_EIN_CONFIRMATION"
17
      | "IRS_EIN_APPLICATION"
18
      | "CERTIFICATE_GOOD_STANDING";
19
  },
20
) {
21
  const url = new URL(
22
    `https://platform.brexapis.com/v1/referrals/${id}/document_upload`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39