//native
type Codat = {
encodedKey: string
}
/**
* Create journal
* The *Create journal* endpoint creates a new [journal](https://docs.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
timeoutInMinutes: string | undefined,
body: {
journalCode?: string
name?: string
type?: string
parentId?: string
hasChildren?: false | true
createdOn?: string
status?: 'Unknown' | 'Active' | 'Archived'
}
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/journals`
)
for (const [k, v] of [['timeoutInMinutes', timeoutInMinutes]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Basic ${auth.encodedKey}`
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago