0
Run Workflow
One script reply has been approved by the moderators Verified
Created by hugo697 32 days ago Viewed 2779 times
0
Submitted by hugo697 Bun
Verified 32 days ago
1
//native
2
type Ai21 = {
3
  apiKey: string;
4
};
5
/**
6
 * Run Workflow
7
 *
8
 */
9
export async function main(
10
  auth: Ai21,
11
  organization_id: string,
12
  data_source: string,
13
  workflow_name: string,
14
) {
15
  const url = new URL(
16
    `https://api.ai21.com/studio/v1/connectors/connected-users/${organization_id}/data-sources/${data_source}/workflows/${workflow_name}/run`,
17
  );
18

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