0

Generate Upload URL for Edge Functions

by
Published Oct 17, 2025

Generate a temporary upload URL that can be used to upload an Edge Functions bundle. • This endpoint is in **Alpha** testing. Please submit any feedback by sending an email to [email protected]. • In order to successfully call this endpoint, the specified Workspace needs to have the Edge Functions feature enabled. Please reach out to your customer success manager for more information.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Generate Upload URL for Edge Functions
8
 * Generate a temporary upload URL that can be used to upload an Edge Functions bundle.
9

10
• This endpoint is in **Alpha** testing.  Please submit any feedback by sending an email to friends@segment.com.
11

12

13
• In order to successfully call this endpoint, the specified Workspace needs to have the Edge Functions feature enabled. Please reach out to your customer success manager for more information.
14
 */
15
export async function main(auth: Segment, sourceId: string) {
16
  const url = new URL(
17
    `${auth.baseUrl}/sources/${sourceId}/edge-functions/upload-url`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      Authorization: "Bearer " + auth.token,
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.text();
32
}
33