//native
type Circleci = {
token: string
}
/**
* Create a usage export
* Submits a request to create a usage export for an organization.
*/
export async function main(
auth: Circleci,
org_id: string,
body: { start: string; end: string; shared_org_ids?: string[] }
) {
const url = new URL(`https://circleci.com/api/v2/organizations/${org_id}/usage_export_job`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Circle-Token': auth.token
},
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 536 days ago