Get All Projects
The getAllProjects endpoint allows you to retrieve all projects associated with the authenticated user. This is useful for displaying a complete list of projects in your application.
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({ userId: "your-user-id", apiKey: "your-api-key",});
async function getAllProjects() { try { const response = await promptTK.getAllProjects(); console.log("Projects:", response); } catch (error) { console.error("Error fetching projects:", error); }}
getAllProjects();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 }, { id: 'project-id-2', name: 'Another Project', description: 'Another description', createdAt: '2024-01-02T00:00:00.000Z', updatedAt: '2024-01-02T00:00:00.000Z', promptCount: 3 } ]}The getAllProjects function makes a request to the following endpoint:
GET /v1/projectsHeaders
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": "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"}- Returns all projects for the authenticated user
- Projects are returned with their prompt count
- If the user has no projects, returns an empty array
- Projects are ordered by creation date (most recent first)