Edits history of script submission #12150 for ' Get projects in a team (figma)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Figma = {
      token: string;
    };
    /**
     * Get projects in a team
     * You can use this endpoint to get a list of all the Projects within the specified team. This will only return projects visible to the authenticated user or owner of the developer token. Note: it is not currently possible to programmatically obtain the team id of a user just from a token. To obtain a team id, navigate to a team page of a team you are a part of. The team id will be present in the URL after the word team and before your team name.
     */
    export async function main(auth: Figma, team_id: string) {
      const url = new URL(`https://api.figma.com/v1/teams/${team_id}/projects`);
    
      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