Edits history of script submission #3307 for ' Update a webhook (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Update a webhook
     * An existing webhook's filters can be updated by making a PUT request on the URL for that webhook. Note that the webhook's previous `filters` array will be completely overwritten by the `filters` sent in the PUT request.
     */
    export async function main(
      auth: Asana,
      webhook_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: {
          filters?: ({
            action?: string;
            fields?: string[];
            resource_subtype?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { [k: string]: unknown } & { [k: string]: unknown })[];
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://app.asana.com/api/1.0/webhooks/${webhook_gid}`);
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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 383 days ago

  • nativets
    type Asana = {
      token: string;
    };
    /**
     * Update a webhook
     * An existing webhook's filters can be updated by making a PUT request on the URL for that webhook. Note that the webhook's previous `filters` array will be completely overwritten by the `filters` sent in the PUT request.
     */
    export async function main(
      auth: Asana,
      webhook_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: {
          filters?: ({
            action?: string;
            fields?: string[];
            resource_subtype?: string;
            resource_type?: string;
            [k: string]: unknown;
          } & { [k: string]: unknown } & { [k: string]: unknown })[];
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://app.asana.com/api/1.0/webhooks/${webhook_gid}`);
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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 937 days ago