//native
type Figma = {
token: string;
};
/**
* Get files in a project
* Get a list of all the Files within the specified project.
*/
export async function main(
auth: Figma,
project_id: string,
branch_data: string | undefined,
) {
const url = new URL(`https://api.figma.com/v1/projects/${project_id}/files`);
for (const [k, v] of [["branch_data", branch_data]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago