0

Bulk Unregister Push Notification Devices

Published Nov 7, 2023

Unregisters the mobile devices that are receiving push notifications. Specify the devices as an array of mobile device tokens. #### Allowed for * Admins

Script zendesk
  • Submitted by hugo697 Typescript (fetch-only)
    Created 566 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * Bulk Unregister Push Notification Devices
    8
     * Unregisters the mobile devices that are receiving push notifications. Specify the devices as an array of mobile device tokens.
    9
    
    
    10
    #### Allowed for
    11
    
    
    12
    * Admins
    13
     */
    14
    export async function main(auth: Zendesk, body: { [k: string]: unknown }) {
    15
      const url = new URL(
    16
        `https://${auth.subdomain}.zendesk.com/api/v2/push_notification_devices/destroy_many`
    17
      );
    18
    
    
    19
      const response = await fetch(url, {
    20
        method: "POST",
    21
        headers: {
    22
          "Content-Type": "application/json",
    23
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    24
        },
    25
        body: JSON.stringify(body),
    26
      });
    27
      if (!response.ok) {
    28
        const text = await response.text();
    29
        throw new Error(`${response.status} ${text}`);
    30
      }
    31
      return await response.text();
    32
    }
    33