//native
type Planetscale = {
serviceTokenId: string;
serviceToken: string;
};
/**
* Create a backup
*
### Authorization
A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
**Service Token Accesses**
`write_backups`
**OAuth Scopes**
| Resource | Scopes |
| :------- | :---------- |
| Organization | `write_backups` |
| Database | `write_backups` |
| Branch | `write_backups` |
*/
export async function main(
auth: Planetscale,
organization: string,
database: string,
branch: string,
body: {
name?: string;
retention_unit?: "hour" | "day" | "week" | "month" | "year";
retention_value?: number;
},
) {
const url = new URL(
`https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches/${branch}/backups`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
},
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