Edits history of script submission #22620 for ' List Schedules (pagerduty)'

  • bunnative
    //native
    
    /**
     * List Schedules
     * List on-call schedules, optionally filtered by a search query.
     */
    export async function main(
      auth: RT.Pagerduty,
      query: string | undefined,
      limit: number | undefined,
      offset: number | undefined,
    ) {
      const url = new URL("https://api.pagerduty.com/schedules")
      if (query !== undefined && query !== "") url.searchParams.append("query", query)
      if (limit !== undefined) url.searchParams.append("limit", String(limit))
      if (offset !== undefined) url.searchParams.append("offset", String(offset))
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Token token=${auth.token}`,
          Accept: "application/vnd.pagerduty+json;version=2",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 days ago