Edits history of script submission #21253 for ' Create tags (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create tags
     *
     */
    export async function main(
      auth: Zoho,
      _module: string,
      color_code: string | undefined,
      body: {
        tags?: {
          name: string;
          color_code:
            | "#57B1FD"
            | "#879BFC"
            | "#658BA8"
            | "#FD87BD"
            | "#969696"
            | "#F48435"
            | "#1DB9B4"
            | "#E7A826"
            | "#63C57E"
            | "#F17574"
            | "#D297EE"
            | "#A8C026"
            | "#B88562";
          created_time: string;
          modified_time: string;
          modified_by: { name: string; id: string; email?: string };
          created_by: { name: string; id: string; email?: string };
          id: string;
        }[];
      },
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/settings/tags`);
      for (const [k, v] of [
        ["module", _module],
        ["color_code", color_code],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago