Edits history of script submission #22754 for ' List Mailings (outreach)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Mailings
     * Lists mailings (sent/scheduled emails), filterable by prospect, state or updatedAt range.
     */
    export async function main(
      auth: RT.Outreach,
      filter_prospect_id: number | undefined,
      filter_state:
        | (
            | "bounced"
            | "delivered"
            | "delivering"
            | "drafted"
            | "failed"
            | "opened"
            | "placeholder"
            | "queued"
            | "replied"
            | "scheduled"
          )
        | undefined,
      filter_updated_at: string | undefined,
      sort: string | undefined,
      page_size: number | undefined,
      page_after: string | undefined
    ) {
      const url = new URL("https://api.outreach.io/api/v2/mailings")
      if (filter_prospect_id !== undefined) {
        url.searchParams.append("filter[prospect][id]", String(filter_prospect_id))
      }
      if (filter_state !== undefined) {
        url.searchParams.append("filter[state]", filter_state)
      }
      if (filter_updated_at !== undefined && filter_updated_at !== "") {
        url.searchParams.append("filter[updatedAt]", filter_updated_at)
      }
      if (sort !== undefined && sort !== "") {
        url.searchParams.append("sort", sort)
      }
      if (page_size !== undefined) {
        url.searchParams.append("page[size]", String(page_size))
      }
      if (page_after !== undefined && page_after !== "") {
        url.searchParams.append("page[after]", page_after)
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/vnd.api+json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago