//native
type Planetscale = {
serviceTokenId: string;
serviceToken: string;
};
/**
* Create a branch
*
### 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**
`create_branch`, `restore_production_branch_backup`, `restore_backup`
**OAuth Scopes**
| Resource | Scopes |
| :------- | :---------- |
| Organization | `write_branches`, `restore_production_branch_backups`, `restore_backups` |
| Database | `write_branches`, `restore_production_branch_backups`, `restore_backups` |
| Branch | `restore_backups` |.
*/
export async function main(
auth: Planetscale,
organization: string,
database: string,
body: { name: string; parent_branch: string; backup_id?: string },
) {
const url = new URL(
`https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches`,
);
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