Edits history of script submission #23322 for ' Create Label (gmail)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Label
     * Create a user label. Nest it under another label with a slash in the name (`Clients/Acme`). Colors must come from Gmail's fixed palette (e.g. `#fb4c2f`, `#16a766`, `#4a86e8`, text `#ffffff`); set both or neither. Requires gmail.labels or gmail.modify on the connection.
     */
    export async function main(
      auth: RT.Gmail,
      name: string,
      label_list_visibility: "labelShow" | "labelShowIfUnread" | "labelHide" = "labelShow",
      message_list_visibility: "show" | "hide" = "show",
      background_color: string | undefined,
      text_color: string | undefined
    ) {
      const response = await fetch(
        "https://gmail.googleapis.com/gmail/v1/users/me/labels",
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            name,
            labelListVisibility: label_list_visibility || "labelShow",
            messageListVisibility: message_list_visibility || "show",
            color:
              background_color || text_color
                ? { backgroundColor: background_color, textColor: text_color }
                : undefined,
          }),
        }
      )
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago