//native
type Codat = {
encodedKey: string
}
/**
* Retrieve sync flow url
* Get a URL for Sync Flow including a one time passcode.
*/
export async function main(
auth: Codat,
commerceKey: string,
accountingKey: string,
merchantIdentifier: string | undefined
) {
const url = new URL(
`https://api.codat.io/config/sync/commerce/${commerceKey}/${accountingKey}/start`
)
for (const [k, v] of [['merchantIdentifier', merchantIdentifier]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago