Edits history of script submission #22756 for ' List Sequence States (outreach)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Sequence States
     * Lists sequence states (prospect ↔ sequence memberships), filterable by prospect, sequence or state.
     */
    export async function main(
      auth: RT.Outreach,
      filter_prospect_id: number | undefined,
      filter_sequence_id: number | undefined,
      filter_state: string | undefined,
      page_size: number | undefined,
      page_after: string | undefined
    ) {
      const url = new URL("https://api.outreach.io/api/v2/sequenceStates")
      if (filter_prospect_id !== undefined) {
        url.searchParams.append("filter[prospect][id]", String(filter_prospect_id))
      }
      if (filter_sequence_id !== undefined) {
        url.searchParams.append("filter[sequence][id]", String(filter_sequence_id))
      }
      if (filter_state !== undefined && filter_state !== "") {
        url.searchParams.append("filter[state]", filter_state)
      }
      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