Get Prompt By Id
The fetchPromptById endpoint allows you to retrieve a specific prompt by its ID from the PromptTK API. This endpoint requires authentication via your user ID and API key.
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({ userId: "your-user-id", apiKey: "your-api-key",});
async function fetchPromptById() { const promptId = "your-prompt-id"; // specify the prompt ID you want to retrieve try { const response = await promptTK.fetchPromptById(promptId); const data = await response.json(); console.log("All Prompts:", data); } catch (error) { console.error("Error fetching prompts:", error); }}fetchPrompts();Expected Output:
{ success: true, message: 'Prompt retrieved successfully', data: { recordId: '<your-prompt-id>', promptName: '<your-prompt-name>', projectId: '<your-project-id>', ownerId: '<your-user-id>', createdAt: 0000000000000, // Timestamp in milliseconds updatedAt: 0000000000000, // Timestamp in milliseconds activeVersionId: '<latest-version-id>', latestVersionNumber: 1 // Version number for the most recent version }}The fetchPromptById function makes a request to the following endpoint:
GET /v1/prompts/byid/:promptIdHeaders
Section titled “Headers”| Header | Description |
|---|---|
userId | Your unique user ID from PromptTK |
apiKey | Your API key from PromptTK |