Can I get a project by its name using search?
can i get a project by its name using search ?
I'll look into the search functionality in the Vercel SDK to see if it can be used to get a project by its name.
I can see there's a search parameter in getprojectsop.ts. Let me look at that file more closely to understand how the search parameter works for getting projects:
Now I can see how the search parameter works. Let me also check the SDK's projects interface to see the full API:
I have a clear answer for you now. Let me also check if there's documentation in the docs folder:
Now I have all the information needed.
##Yes, you can get a project by its name using search!
The getProjects method supports a search parameter that filters projects by their name. Here's how it works:
###From the source code (src/models/getprojectsop.ts [blocked]):
/**
* Search projects by the name field
*/
search?: string | undefined;
###Usage example:
const result = await vercel.projects.getProjects({
search: "my-project-name"
});
###Important notes:
-
It returns a list - The
searchparameter filters the project list, so you'll get an array of matching projects, not a single project. You'll need to iterate or pick the first result. -
Partial matching - The search likely performs a partial/fuzzy match on the name field, so searching for
"my-proj"might return"my-project","my-project-2", etc. -
If you need an exact match, you might want to:
- Use
searchand then filter the results for an exact name match - Or use other project methods like
updateProjectordeleteProjectwhich accept the project name directly viaidOrNameparameter (as shown in the source: "Update the fields of a project using either itsnameorid" and "Delete a specific project by passing either the projectidorname")
- Use
Would you like me to show you more details about how to work with the search results or other ways to get a project by name?
great! and what if i want to get branch URL of a branch in a project?
Let me search for branch URL related functionality in the SDK.
I can see there's a branch filter on getDeployments. Let me also check the project domains which seem to have gitBranch association:
Now let me check what the deployment response contains, specifically looking for the URL:
Now I have a complete picture. Let me summarize what I found:
##Getting a Branch URL
The Vercel SDK doesn't have a direct method to get a "branch URL". However, there are a few approaches you can use:
###Option 1: List Deployments filtered by branch
The getDeployments method supports filtering by branch:
const deployments = await vercel.deployments.getDeployments({
projectId: "your-project-id",
branch: "feature-branch", // Filter by branch name
state: "READY", // Only ready deployments
limit: 1 // Get latest one
});
// Get the URL from the deployment
const branchUrl = deployments.deployments[0]?.url;
From src/models/getdeploymentsop.ts [blocked]:
/**
* Filter deployments based on the branch name
*/
branch?: string | undefined;
Each deployment in the response includes a url property (line 446 [blocked]):
/**
* The URL of the deployment.
*/
url: string;
###Option 2: Get Project Domains filtered by branch
You can list domains associated with a specific git branch:
const domains = await vercel.projects.getProjectDomains({
idOrName: "your-project",
gitBranch: "feature-branch" // Filter domains by branch
});
// Each domain has a name which is the URL
const branchDomainUrl = domains.domains[0]?.name;
From src/models/getprojectdomainsop.ts [blocked]:
/**
* Filters domains based on specific branch.
*/
gitBranch?: string | undefined;
###Which approach to use?
- Use
getDeploymentsif you want the latest deployment URL for a specific branch - Use
getProjectDomainsif you have custom domains configured per branch (domains return the configured domain name, not just deployment URLs)
Would you like more details on either approach?
getDeployments sounds good. what if i want getDeploymentURLByBranchOrCommit({ project, branchOrCommit })?
That's a good use case! The SDK doesn't have that exact method built-in, but you can build it using getDeployments. Let me check the available filters:
The SDK has both branch and sha (commit) filters. Here's how you could implement getDeploymentURLByBranchOrCommit:
import { Vercel } from "@vercel/sdk";
interface GetDeploymentURLOptions {
project: string;
branchOrCommit: string;
teamId?: string;
}
async function getDeploymentURLByBranchOrCommit(
vercel: Vercel,
{ project, branchOrCommit, teamId }: GetDeploymentURLOptions
): Promise<string | null> {
// First, try to find by branch name
const byBranch = await vercel.deployments.getDeployments({
projectId: project,
branch: branchOrCommit,
state: "READY",
limit: 1,
teamId,
});
if (byBranch.deployments.length > 0) {
return byBranch.deployments[0].url;
}
// If not found by branch, try by commit SHA
const bySha = await vercel.deployments.getDeployments({
projectId: project,
sha: branchOrCommit,
state: "READY",
limit: 1,
teamId,
});
if (bySha.deployments.length > 0) {
return bySha.deployments[0].url;
}
return null;
}
###Usage:
const vercel = new Vercel({ bearerToken: "your-token" });
// By branch name
const url1 = await getDeploymentURLByBranchOrCommit(vercel, {
project: "my-project-id",
branchOrCommit: "feature-branch",
});
// By commit SHA
const url2 = await getDeploymentURLByBranchOrCommit(vercel, {
project: "my-project-id",
branchOrCommit: "abc123def456",
});
###Key filters from the SDK:
| Filter | Description |
|---|---|
branch | Filter deployments based on the branch name |
sha | Filter deployments based on the commit SHA |
state | Filter by state (READY, BUILDING, ERROR, etc.) |
limit | Maximum number of deployments to return |
projectId | Filter by project ID or name |
Note: The function tries branch first, then falls back to SHA. If you know ahead of time which one you're passing, you could optimize by only making one API call. You could also detect SHA format (40-char hex string) to decide which filter to use first.
END OF POST
Claude Opus 4.5