Get Recent Projects
The getRecentProjects endpoint allows you to retrieve the most recently created projects. This is useful for displaying a “Recent Projects” section in your application or for quick access to active projects.
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({ userId: "your-user-id", apiKey: "your-api-key",});
async function getRecentProjects() { const limit = 3; // Get 3 most recent projects
try { const response = await promptTK.getRecentProjects(limit); console.log("Recent Projects:", response); } catch (error) { console.error("Error fetching recent projects:", error); }}
getRecentProjects();Expected Output:
{ success: true, message: 'Recent projects retrieved successfully', data: [ { id: 'project-id-3', name: 'Newest Project', description: 'Created today', createdAt: '2024-01-15T12:00:00.000Z', updatedAt: '2024-01-15T12:00:00.000Z', promptCount: 2 }, { id: 'project-id-2', name: 'Recent Project', description: 'Created yesterday', createdAt: '2024-01-14T10:00:00.000Z', updatedAt: '2024-01-14T10:00:00.000Z', promptCount: 5 }, { id: 'project-id-1', name: 'Older Project', description: 'Created last week', createdAt: '2024-01-08T08:00:00.000Z', updatedAt: '2024-01-08T08:00:00.000Z', promptCount: 10 } ]}The getRecentProjects function makes a request to the following endpoint:
POST /v1/projects/recentRequest Body
Section titled “Request Body”{ "limit": 3}Headers
Section titled “Headers”| Header | Value |
|---|---|
Content-Type | application/json |
Authorization | Bearer your-api-key |
x-user-id | your-user-id |
Response
Section titled “Response”On success (200 OK):
{ "success": true, "message": "Recent 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"}- Projects are ordered by creation date (most recent first)
- The
limitparameter determines how many recent projects to return - If limit is greater than total projects, returns all projects
- Useful for dashboard “Recent Projects” widgets
- Default limit can be set based on your UI requirements (typically 3-5)