export type Payment = {paymentId?: number | undefined, date: string, account: string, amount: number, amountInNok?: number | undefined, currency?: string | undefined, fee?: number | undefined}; export type DraftLineRequest = {text: string, vatType: string, incomeAccount: string, net: number, gross: number, projectId?: number | undefined}; export type DraftRequest = {invoiceIssueDate?: string | undefined, dueDate?: string | undefined, invoiceNumber?: string | undefined, contactId?: number | undefined, projectId?: number | undefined, cash: boolean, currency?: string | undefined, kid?: string | undefined, paid: boolean, payments?: Array | undefined, lines: Array}; export type CreateApiCompaniesCompanySlugPurchasesDraftsArgs = {body: DraftRequest}; export type CreateApiCompaniesCompanySlugPurchasesDraftsOptions = {baseUrl?: string | undefined, fikenApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a purchase draft. * * POST /companies/{companySlug}/purchases/drafts */ export const createApiCompaniesCompanySlugPurchasesDrafts = async (args: CreateApiCompaniesCompanySlugPurchasesDraftsArgs, options?: CreateApiCompaniesCompanySlugPurchasesDraftsOptions) => { const {baseUrl = "https://api.fiken.no/api/v2", fetch: fetchFn = fetch, fikenApiOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (fikenApiOauth !== undefined) headers.set('authorization', `Bearer ${fikenApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companySlug))}/purchases/drafts${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 };