0

Get 3D models by user ID

by
Published Apr 8, 2025

This endpoint returns all 3D models by a specific user

Script leonardoai Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Leonardoai = {
3
  apiKey: string;
4
};
5
/**
6
 * Get 3D models by user ID
7
 * This endpoint returns all 3D models by a specific user
8
 */
9
export async function main(
10
  auth: Leonardoai,
11
  userId: string,
12
  offset: string | undefined,
13
  limit: string | undefined,
14
  body: { userId?: string },
15
) {
16
  const url = new URL(
17
    `https://cloud.leonardo.ai/api/rest/v1/models-3d/user/${userId}`,
18
  );
19
  for (const [k, v] of [
20
    ["offset", offset],
21
    ["limit", limit],
22
  ]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.apiKey,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41