Skip to content

Get Projects with Limit

The getProjectsWithLimit endpoint allows you to retrieve a specific number of projects for pagination or performance optimization. This is useful when you want to display only the first few projects or implement pagination.

import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
async function getProjectsWithLimit() {
const limit = 5; // Get first 5 projects
try {
const response = await promptTK.getProjectsWithLimit(limit);
console.log("Projects:", response);
} catch (error) {
console.error("Error fetching projects:", error);
}
}
getProjectsWithLimit();

Expected Output:

{
success: true,
message: 'Projects retrieved successfully',
data: [
{
id: 'project-id-1',
name: 'My First Project',
description: 'Project description',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z',
promptCount: 5
},
// ... up to 5 projects
]
}

The getProjectsWithLimit function makes a request to the following endpoint:

POST /v1/projects/limit
{
"limit": 5
}
HeaderValue
Content-Typeapplication/json
AuthorizationBearer your-api-key
x-user-idyour-user-id

On success (200 OK):

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

On error:

{
"success": false,
"message": "Error message",
"error": "Detailed error information"
}
  • The limit parameter must be a positive integer
  • If limit is greater than total projects, returns all projects
  • Projects are ordered by creation date (most recent first)
  • Useful for implementing pagination or limiting initial data load
  • If no limit is provided, defaults to returning all projects