Edits history of script submission #23346 for ' List Events (ms_outlook)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    export type DynSelect_calendar = string
    
    export async function calendar(auth: RT.MsOutlook) {
      const r = await fetch(
        "https://graph.microsoft.com/v1.0/me/calendars?$top=100&$select=id,name",
        {
          headers: {
            Authorization: `Bearer ${auth.token}`,
            Accept: "application/json",
          },
        }
      )
      if (!r.ok) throw new Error(`${r.status} ${await r.text()}`)
      const { value } = (await r.json()) as {
        value: { id: string; name: string }[]
      }
      return value.map((c) => ({ value: c.id, label: c.name }))
    }
    
    /**
     * List Events
     * List events from the default calendar or a chosen one. With both `start_date_time` and `end_date_time` (ISO 8601, e.g. `2026-01-01T00:00:00Z`) it returns every occurrence in that window, recurring ones expanded; without them it returns single events and series masters. `filter` takes OData (e.g. `contains(subject,'standup')`). Pass the returned `@odata.nextLink` as `next_link` for the next page. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
     */
    export async function main(
      auth: RT.MsOutlook,
      start_date_time: string | undefined,
      end_date_time: string | undefined,
      calendar: DynSelect_calendar | undefined,
      filter: string | undefined,
      order_by: string | undefined,
      select: string | undefined,
      top: number = 25,
      next_link: string | undefined,
      time_zone: string = "UTC"
    ) {
      const base = `https://graph.microsoft.com/v1.0/me${
        calendar != null && calendar !== ""
          ? `/calendars/${encodeURIComponent(calendar)}`
          : ""
      }`
      if (
        next_link != null &&
        next_link !== "" &&
        !next_link.startsWith("https://graph.microsoft.com/")
      ) {
        throw new Error(
          "next_link must be an @odata.nextLink returned by Microsoft Graph"
        )
      }
      let url: URL
      if (next_link != null && next_link !== "") {
        url = new URL(next_link)
      } else {
        const windowed =
          start_date_time != null &&
          start_date_time !== "" &&
          end_date_time != null &&
          end_date_time !== ""
        url = new URL(`${base}/${windowed ? "calendarView" : "events"}`)
        if (windowed) {
          url.searchParams.append("startDateTime", start_date_time!)
          url.searchParams.append("endDateTime", end_date_time!)
        }
        url.searchParams.append("$top", String(top))
        if (filter != null && filter !== "") {
          url.searchParams.append("$filter", filter)
        }
        if (order_by != null && order_by !== "") {
          url.searchParams.append("$orderby", order_by)
        }
        if (select != null && select !== "") {
          url.searchParams.append("$select", select)
        }
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
          Prefer: `outlook.timezone="${time_zone}"`,
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago

  • bunnative
    //native
    
    export type DynSelect_calendar = string
    
    export async function calendar(auth: RT.Outlook) {
      const r = await fetch(
        "https://graph.microsoft.com/v1.0/me/calendars?$top=100&$select=id,name",
        {
          headers: {
            Authorization: `Bearer ${auth.token}`,
            Accept: "application/json",
          },
        }
      )
      if (!r.ok) throw new Error(`${r.status} ${await r.text()}`)
      const { value } = (await r.json()) as {
        value: { id: string; name: string }[]
      }
      return value.map((c) => ({ value: c.id, label: c.name }))
    }
    
    /**
     * List Events
     * List events from the default calendar or a chosen one. With both `start_date_time` and `end_date_time` (ISO 8601, e.g. `2026-01-01T00:00:00Z`) it returns every occurrence in that window, recurring ones expanded; without them it returns single events and series masters. `filter` takes OData (e.g. `contains(subject,'standup')`). Pass the returned `@odata.nextLink` as `next_link` for the next page. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
     */
    export async function main(
      auth: RT.Outlook,
      start_date_time: string | undefined,
      end_date_time: string | undefined,
      calendar: DynSelect_calendar | undefined,
      filter: string | undefined,
      order_by: string | undefined,
      select: string | undefined,
      top: number = 25,
      next_link: string | undefined,
      time_zone: string = "UTC"
    ) {
      const base = `https://graph.microsoft.com/v1.0/me${
        calendar != null && calendar !== ""
          ? `/calendars/${encodeURIComponent(calendar)}`
          : ""
      }`
      if (
        next_link != null &&
        next_link !== "" &&
        !next_link.startsWith("https://graph.microsoft.com/")
      ) {
        throw new Error(
          "next_link must be an @odata.nextLink returned by Microsoft Graph"
        )
      }
      let url: URL
      if (next_link != null && next_link !== "") {
        url = new URL(next_link)
      } else {
        const windowed =
          start_date_time != null &&
          start_date_time !== "" &&
          end_date_time != null &&
          end_date_time !== ""
        url = new URL(`${base}/${windowed ? "calendarView" : "events"}`)
        if (windowed) {
          url.searchParams.append("startDateTime", start_date_time!)
          url.searchParams.append("endDateTime", end_date_time!)
        }
        url.searchParams.append("$top", String(top))
        if (filter != null && filter !== "") {
          url.searchParams.append("$filter", filter)
        }
        if (order_by != null && order_by !== "") {
          url.searchParams.append("$orderby", order_by)
        }
        if (select != null && select !== "") {
          url.searchParams.append("$select", select)
        }
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
          Prefer: `outlook.timezone="${time_zone}"`,
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 11 hours ago

  • bunnative
    //native
    
    export type DynSelect_calendar = string
    
    export async function calendar(auth: RT.Outlook) {
      const r = await fetch(
        "https://graph.microsoft.com/v1.0/me/calendars?$top=100&$select=id,name",
        {
          headers: {
            Authorization: `Bearer ${auth.token}`,
            Accept: "application/json",
          },
        }
      )
      if (!r.ok) throw new Error(`${r.status} ${await r.text()}`)
      const { value } = (await r.json()) as {
        value: { id: string; name: string }[]
      }
      return value.map((c) => ({ value: c.id, label: c.name }))
    }
    
    /**
     * List Events
     * List events from the default calendar or a chosen one. With both `start_date_time` and `end_date_time` (ISO 8601, e.g. `2026-01-01T00:00:00Z`) it returns every occurrence in that window, recurring ones expanded; without them it returns single events and series masters. `filter` takes OData (e.g. `contains(subject,'standup')`). Pass the returned `@odata.nextLink` as `next_link` for the next page. Requires Calendars.Read on the connection.
     */
    export async function main(
      auth: RT.Outlook,
      start_date_time: string | undefined,
      end_date_time: string | undefined,
      calendar: DynSelect_calendar | undefined,
      filter: string | undefined,
      order_by: string | undefined,
      select: string | undefined,
      top: number = 25,
      next_link: string | undefined,
      time_zone: string = "UTC"
    ) {
      const base = `https://graph.microsoft.com/v1.0/me${
        calendar != null && calendar !== ""
          ? `/calendars/${encodeURIComponent(calendar)}`
          : ""
      }`
      if (
        next_link != null &&
        next_link !== "" &&
        !next_link.startsWith("https://graph.microsoft.com/")
      ) {
        throw new Error(
          "next_link must be an @odata.nextLink returned by Microsoft Graph"
        )
      }
      let url: URL
      if (next_link != null && next_link !== "") {
        url = new URL(next_link)
      } else {
        const windowed =
          start_date_time != null &&
          start_date_time !== "" &&
          end_date_time != null &&
          end_date_time !== ""
        url = new URL(`${base}/${windowed ? "calendarView" : "events"}`)
        if (windowed) {
          url.searchParams.append("startDateTime", start_date_time!)
          url.searchParams.append("endDateTime", end_date_time!)
        }
        url.searchParams.append("$top", String(top))
        if (filter != null && filter !== "") {
          url.searchParams.append("$filter", filter)
        }
        if (order_by != null && order_by !== "") {
          url.searchParams.append("$orderby", order_by)
        }
        if (select != null && select !== "") {
          url.searchParams.append("$select", select)
        }
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
          Prefer: `outlook.timezone="${time_zone}"`,
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 11 hours ago