Skip to content

Get Project by ID

The getProjectById endpoint allows you to retrieve detailed information about a specific project using its unique identifier. This is useful when you need to display or work with a particular project.

import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
async function getProjectById() {
const projectId = "abc123xyz789";
try {
const response = await promptTK.getProjectById(projectId);
console.log("Project details:", response);
} catch (error) {
console.error("Error fetching project:", error);
}
}
getProjectById();

Expected Output:

{
success: true,
message: 'Project retrieved successfully',
data: {
id: 'abc123xyz789',
name: 'My Project',
description: 'Project description',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-15T12:00:00.000Z',
promptCount: 15,
prompts: [
{
id: 'prompt-1',
name: 'Prompt Name',
createdAt: '2024-01-02T00:00:00.000Z'
},
// ... more prompts
]
}
}

The getProjectById function makes a request to the following endpoint:

POST /v1/projects/byid
{
"projectId": "string" // required
}
HeaderValue
Content-Typeapplication/json
AuthorizationBearer your-api-key
x-user-idyour-user-id

On success (200 OK):

{
"success": true,
"message": "Project retrieved successfully",
"data": {
"id": "string",
"name": "string",
"description": "string",
"createdAt": "ISO 8601 timestamp",
"updatedAt": "ISO 8601 timestamp",
"promptCount": "number",
"prompts": [
{
"id": "string",
"name": "string",
"createdAt": "ISO 8601 timestamp"
}
]
}
}

On error:

{
"success": false,
"message": "Project ID is required"
}

or

{
"success": false,
"message": "Project not found"
}

or

{
"success": false,
"message": "Unauthorized access to project"
}
  • The projectId parameter is required
  • The endpoint verifies that the project belongs to the authenticated user
  • Returns detailed project information including associated prompts
  • Useful for displaying project details pages or editing project information
  • If the project doesn’t exist or doesn’t belong to the user, returns an error