Edits history of script submission #22136 for ' Update territory (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update territory
     *
     */
    export async function main(
      auth: Zoho,
      id: string,
      body: {
        territories?: {
          created_time: string;
          modified_time: string;
          manager: { name: string; id: string };
          reporting_to: { name: string; id: string };
          permission_type: "read_write_delete" | "read_only";
          modified_by: { name: string; id: string; email?: string };
          description: string;
          id: string;
          created_by: { name: string; id: string; email?: string };
          account_rule_criteria: {
            comparator: string;
            field: { api_name: string; id: string };
            value: {};
            group_operator: string;
            group: {}[];
          };
          deal_rule_criteria: {
            comparator: string;
            field: { api_name: string; id: string };
            value: {};
            group_operator: string;
            group: {}[];
          };
          lead_rule_criteria?: {
            comparator: string;
            field: { api_name: string; id: string };
            value: {};
            group_operator: string;
            group: {}[];
          };
          name: string;
          api_name: string;
        }[];
      },
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/settings/territories/${id}`);
    
      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