export type FileRequest = {fileId: string}; export type CreateSubmissionMessageRequest = {subject: string, body: string, files?: (Array | null) | undefined, shouldUseOrganizationEmailAsFromAddress?: boolean | undefined}; export type SendMessageToEntriesRequest = {entryIds: Array, message: CreateSubmissionMessageRequest}; export type CreateApiV4EntriesMessageArgs = {body: SendMessageToEntriesRequest}; export type CreateApiV4EntriesMessageOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send message to entries * * POST /v4/entries/message */ export const createApiV4EntriesMessage = async (args: CreateApiV4EntriesMessageArgs, options?: CreateApiV4EntriesMessageOptions) => { const {baseUrl = "https://submittable-api.submittable.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v4/entries/message${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 undefined };