Edits history of script submission #22147 for ' Update variable by api name (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update variable by api name
     *
     */
    export async function main(
      auth: Zoho,
      api_name: string,
      group: string | undefined,
      body: {
        variables: {
          api_name: string;
          name: string;
          description: string;
          source: string;
          id: string;
          type:
            | "date"
            | "website"
            | "double"
            | "textarea"
            | "integer"
            | "percent"
            | "long"
            | "datetime"
            | "phone"
            | "checkbox"
            | "currency"
            | "text"
            | "email";
          variable_group: { id: string; api_name: string; name: string };
          read_only: false | true;
          value: {};
        }[];
      },
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/settings/variables/${api_name}`,
      );
      for (const [k, v] of [["group", group]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        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