Edits history of script submission #21451 for ' Enable notifications (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Enable notifications
     *
     */
    export async function main(
      auth: Zoho,
      body: {
        watch?: {
          channel_id: string;
          notify_url: string;
          events: string[];
          token?: string;
          fields?: {};
          notify_on_related_action?: false | true;
          return_affected_field_values?: false | true;
          _delete_events?: true;
          resource_name?: string;
          channel_expiry?: string;
          resource_id?: string;
          resource_uri?: string;
          notification_condition?: {
            type?: string;
            module: { api_name?: string; id?: string };
            field_selection: {
              comparator: string;
              field: { api_name: string; id: string };
              value: {};
              group_operator: string;
              group: {}[];
            };
          }[];
        }[];
      },
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/actions/watch`);
    
      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