export type GetApiOpportunitiesArgs = {search?: string | undefined, id?: number | undefined, name?: string | undefined, status?: string | undefined, stage?: number | undefined, 'stage.name'?: string | undefined, owner?: number | undefined, team_member?: number | undefined, owner_group?: number | undefined, assignee_group?: number | undefined, team_member_group?: number | undefined, account?: number | undefined, assignee?: number | undefined, min_value?: number | undefined, max_value?: number | undefined, close_after?: string | undefined, close_before?: string | undefined, creation_after?: string | undefined, creation_before?: string | undefined, closed?: boolean | undefined, done?: boolean | undefined, tag?: Array | undefined, 'tag.name'?: string | undefined, hotness?: number | undefined, limit?: number | undefined, offset?: number | undefined, order_by?: Array | undefined, pipeline?: number | undefined, custom?: string | undefined, details?: boolean | undefined, export?: string | undefined, q?: string | undefined}; export type GetApiOpportunitiesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * List opportunities * * GET /opportunities */ export const getApiOpportunities = async (args: GetApiOpportunitiesArgs, options?: GetApiOpportunitiesOptions) => { const {baseUrl = "https://api.salesflare.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.search != null) query.append("search", String(args.search)) if (args.id != null) query.append("id", String(args.id)) if (args.name != null) query.append("name", String(args.name)) if (args.status != null) query.append("status", String(args.status)) if (args.stage != null) query.append("stage", String(args.stage)) if (args['stage.name'] != null) query.append("stage.name", String(args['stage.name'])) if (args.owner != null) query.append("owner", String(args.owner)) if (args.team_member != null) query.append("team_member", String(args.team_member)) if (args.owner_group != null) query.append("owner_group", String(args.owner_group)) if (args.assignee_group != null) query.append("assignee_group", String(args.assignee_group)) if (args.team_member_group != null) query.append("team_member_group", String(args.team_member_group)) if (args.account != null) query.append("account", String(args.account)) if (args.assignee != null) query.append("assignee", String(args.assignee)) if (args.min_value != null) query.append("min_value", String(args.min_value)) if (args.max_value != null) query.append("max_value", String(args.max_value)) if (args.close_after != null) query.append("close_after", String(args.close_after)) if (args.close_before != null) query.append("close_before", String(args.close_before)) if (args.creation_after != null) query.append("creation_after", String(args.creation_after)) if (args.creation_before != null) query.append("creation_before", String(args.creation_before)) if (args.closed != null) query.append("closed", String(args.closed)) if (args.done != null) query.append("done", String(args.done)) for (const item of args.tag ?? []) query.append("tag", String(item)) if (args['tag.name'] != null) query.append("tag.name", String(args['tag.name'])) if (args.hotness != null) query.append("hotness", String(args.hotness)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) for (const item of args.order_by ?? []) query.append("order_by", String(item)) if (args.pipeline != null) query.append("pipeline", String(args.pipeline)) if (args.custom != null) query.append("custom", String(args.custom)) if (args.details != null) query.append("details", String(args.details)) if (args.export != null) query.append("export", String(args.export)) if (args.q != null) query.append("q", String(args.q)) const url = `${baseUrl.replace(/\/+$/, '')}/opportunities${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };