Edits history of script submission #3608 for ' Get all projects (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get all projects
     * Returns all projects visible to the user. Deprecated, use [ Get projects paginated](#api-rest-api-2-project-search-get) that supports search and pagination.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** Projects are returned only where the user has *Browse Projects* or *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
     */
    export async function main(
      auth: Jira,
      expand: string | undefined,
      recent: string | undefined,
      properties: string | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/project`
      );
      for (const [k, v] of [
        ["expand", expand],
        ["recent", recent],
        ["properties", properties],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get all projects
     * Returns all projects visible to the user. Deprecated, use [ Get projects paginated](#api-rest-api-2-project-search-get) that supports search and pagination.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** Projects are returned only where the user has *Browse Projects* or *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
     */
    export async function main(
      auth: Jira,
      expand: string | undefined,
      recent: string | undefined,
      properties: string | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/project`
      );
      for (const [k, v] of [
        ["expand", expand],
        ["recent", recent],
        ["properties", properties],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 948 days ago