Edits history of script submission #3525 for ' Register dynamic webhooks (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Register dynamic webhooks
     * Registers webhooks.
    
    **NOTE:** for non-public OAuth apps, webhooks are delivered only if there is a match between the app owner and the user who registered a dynamic webhook.
    
    **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
     */
    export async function main(
      auth: Jira,
      body: {
        url: string;
        webhooks: {
          events: (
            | "jira:issue_created"
            | "jira:issue_updated"
            | "jira:issue_deleted"
            | "comment_created"
            | "comment_updated"
            | "comment_deleted"
            | "issue_property_set"
            | "issue_property_deleted"
          )[];
          fieldIdsFilter?: string[];
          issuePropertyKeysFilter?: string[];
          jqlFilter: string;
        }[];
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/webhook`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        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 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Register dynamic webhooks
     * Registers webhooks.
    
    **NOTE:** for non-public OAuth apps, webhooks are delivered only if there is a match between the app owner and the user who registered a dynamic webhook.
    
    **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
     */
    export async function main(
      auth: Jira,
      body: {
        url: string;
        webhooks: {
          events: (
            | "jira:issue_created"
            | "jira:issue_updated"
            | "jira:issue_deleted"
            | "comment_created"
            | "comment_updated"
            | "comment_deleted"
            | "issue_property_set"
            | "issue_property_deleted"
          )[];
          fieldIdsFilter?: string[];
          issuePropertyKeysFilter?: string[];
          jqlFilter: string;
        }[];
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/webhook`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        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 948 days ago