export type CreateApiMessagesArgs = {body: {account: number, body: string, mentions?: Array | undefined, date?: string | undefined}}; export type CreateApiMessagesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an internal note * * POST /messages */ export const createApiMessages = async (args: CreateApiMessagesArgs, options?: CreateApiMessagesOptions) => { const {baseUrl = "https://api.salesflare.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") const url = `${baseUrl.replace(/\/+$/, '')}/messages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };