N
Neon2y ago
evident-indigo

Documentation for how to use Neon API to create a branch

i'm not able to create a branch with the nodejs API. I'm getting the error Object literal may only specify known properties, and 'name' does not exist in type 'BranchCreateRequest'.ts(2353) This is my code snippet:
export const createBranch = async ({
projectId,
branchName,
}: {
projectId: string;
branchName: string;
}) => {
const response = await neonClient.createProjectBranch(PROJECT_ID, {
name: branchName,
});

if (response.status !== StatusCodes.OK) {
throw Error(
`Failed to create branch ${branchName} for project ${projectId}. Status: ${response.status}`
);
}

return response.data.branch;
};
export const createBranch = async ({
projectId,
branchName,
}: {
projectId: string;
branchName: string;
}) => {
const response = await neonClient.createProjectBranch(PROJECT_ID, {
name: branchName,
});

if (response.status !== StatusCodes.OK) {
throw Error(
`Failed to create branch ${branchName} for project ${projectId}. Status: ${response.status}`
);
}

return response.data.branch;
};
I'm using @neondatabase/api-client version 1.8.0
4 Replies
foreign-sapphire
foreign-sapphire2y ago
instead of
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
name: branchName,
});
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
name: branchName,
});
try
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
branch: {
name: branchName
}
});
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
branch: {
name: branchName
}
});
evident-indigo
evident-indigoOP2y ago
can you provide the other parameters for branch? @andyhats I want to also specify the branch to branch off of
foreign-sapphire
foreign-sapphire2y ago
Neon
Create a branch
Creates a branch in the specified project.<br/>You can obtain a <button aria-label="Copy Code" class="rdmd-code-copy fa"></button>project_id by listing the projects for your Neon account.This method does not require a request body, but you can specify one to create a compute endpoi...
foreign-sapphire
foreign-sapphire2y ago
so
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
branch: {
name: branchName,
parent_id: 'br-quiet-king-637'
}
});
const response = await neonClient.createProjectBranch(SUTRO_WEST_PROJECT_ID, {
branch: {
name: branchName,
parent_id: 'br-quiet-king-637'
}
});

Did you find this page helpful?