The `getAllPrompts` API endpoint is a part of the `swarms.world` application, designed to fetch all prompt records from the database. This endpoint is crucial for retrieving various prompts stored in the `swarms_cloud_prompts` table, including their metadata such as name, description, use cases, and tags. It provides an authenticated way to access this data, ensuring that only authorized users can retrieve the information.
The `getAllPrompts` API endpoint is a part of the `swarms.world` application, designed to fetch all prompt records from the database. This endpoint is crucial for retrieving various prompts stored in the `swarms_cloud_prompts` table, including their metadata such as name, description, use cases, and tags.
## Purpose
The primary purpose of this API endpoint is to provide a secure method for clients to fetch a list of prompts stored in the `swarms_cloud_prompts` table. It ensures data integrity and security by using an authentication guard and handles various HTTP methods and errors gracefully.
The primary purpose of this API endpoint is to provide a method for clients to fetch a list of prompts stored in the `swarms_cloud_prompts` table, with the ability to filter by name, tags, and use cases.
| Authorization | String | Yes | Bearer token for API access |
- **name** (optional): A substring to match against the prompt name. The query is case-insensitive.
- **tag** (optional): A comma-separated list of tags to filter prompts by. The query matches any of the provided tags, and is case-insensitive.
- **use_case** (optional): A substring to match against the use case titles within the `use_cases` array. The query is case-insensitive.
- **use_case_description** (optional): A substring to match against the use case descriptions within the `use_cases` array. The query is case-insensitive.
### Response
#### Response
#### Success Response (200)
##### Success Response (200)
Returns an array of prompts.
@ -39,14 +42,19 @@ Returns an array of prompts.
"name": "string",
"description": "string",
"prompt": "string",
"use_cases": "string",
"use_cases": [
{
"title": "string",
"description": "string"
}
],
"tags": "string"
},
...
]
```
#### Error Responses
##### Error Responses
- **405 Method Not Allowed**
@ -56,11 +64,57 @@ Returns an array of prompts.
}
```
- **401 Unauthorized**
- **500 Internal Server Error**
```json
{
"error": "Could not fetch prompts"
}
```
### Fetch Prompt by ID
#### Endpoint URL
```
https://swarms.world/get-prompts/[id]
```
#### HTTP Method
```
GET
```
#### Response
##### Success Response (200)
Returns a single prompt by ID.
```json
{
"id": "string",
"name": "string",
"description": "string",
"prompt": "string",
"use_cases": [
{
"title": "string",
"description": "string"
}
],
"tags": "string"
}
```
##### Error Responses
- **404 Not Found**
```json
{
"error": "API Key is missing"
"error": "Prompt not found"
}
```
@ -68,31 +122,50 @@ Returns an array of prompts.
```json
{
"error": "Could not fetch prompts"
"error": "Could not fetch prompt"
}
```
## Request Handling
### Request Handling
1. **Method Validation**: The endpoint only supports the `GET` method. If a different HTTP method is used, it responds with a `405 Method Not Allowed` status.
2. **Authentication**: The request must include a valid Bearer token in the `Authorization` header. If the token is missing, a `401 Unauthorized` status is returned.
3. **Authorization Check**: The token is validated using the `AuthApiGuard` class. If the token is invalid, an appropriate error response is returned based on the status received from the guard.
4. **Database Query**: The endpoint queries the `swarms_cloud_prompts` table using the `supabaseAdmin` client to fetch prompt data.
5. **Response**: On success, it returns the prompt data in JSON format. In case of an error during the database query, a `500 Internal Server Error` status is returned.
## Code Example
2. **Database Query**:
### JavaScript (Node.js)
- **Fetching All Prompts**: The endpoint uses the `supabaseAdmin` client to query the `swarms_cloud_prompts` table. Filters are applied based on the query parameters (`name`, `tag`, and `use_cases`).
- **Fetching a Prompt by ID**: The endpoint retrieves a single prompt from the `swarms_cloud_prompts` table by its unique ID.
```javascript
import fetch from 'node-fetch';
3. **Response**: On success, it returns the prompt data in JSON format. In case of an error during the database query, a `500 Internal Server Error` status is returned. For fetching by ID, if the prompt is not found, it returns a `404 Not Found` status.
This documentation provides a comprehensive guide to the `getAllPrompts` API endpoint, including usage examples in multiple programming languages and detailed attribute descriptions.
This documentation provides a comprehensive guide to the `getAllPrompts` API endpoint, including usage examples in multiple programming languages and detailed attribute descriptions.
The `https://swarms.world/api/add-prompt` endpoint allows users to add a new prompt to the Swarms platform. This API accepts a POST request with a JSON body containing details of the prompt, such as its name, description, use cases, and tags. The request must be authenticated using an API key.
## Endpoint
## Endpoint: Add Prompt
- **URL:**`https://swarms.world/api/add-prompt`
- **Method:** POST
@ -14,22 +13,22 @@ The `https://swarms.world/api/add-prompt` endpoint allows users to add a new pro
The request body should be a JSON object with the following attributes:
prompt: 'This is an example prompt from an API route.',
description: 'Description of the prompt.',
name: "Example Prompt",
prompt: "This is an example prompt from an API route.",
description: "Description of the prompt.",
useCases: [
{ title: 'Use case 1', description: 'Description of use case 1' },
{ title: 'Use case 2', description: 'Description of use case 2' }
{ title: "Use case 1", description: "Description of use case 1" },
{ title: "Use case 2", description: "Description of use case 2" },
],
tags: 'example, prompt'
})
tags: "example, prompt",
}),
});
const result = await response.json();
console.log(result);
} catch (error) {
console.error('An error has occurred', error);
console.error("An error has occurred", error);
}
}
@ -178,6 +177,202 @@ The response will be a JSON object containing the result of the operation. Examp
}
```
# Endpoint: Edit Prompt
The `https://swarms.world/api/edit-prompt` endpoint allows users to edit an existing prompt on the Swarms platform. This API accepts a POST request with a JSON body containing the prompt details to be updated, such as its name, description, use cases, and tags. The request must be authenticated using an API key.
## Endpoint
- **URL:**`https://swarms.world/api/edit-prompt`
- **Method:** POST
- **Content-Type:**`application/json`
- **Authorization:** Bearer token required in the header
## Request Parameters
The request body should be a JSON object with the following attributes:
This comprehensive documentation provides all the necessary information to effectively use the `https://swarms.world/api/add-prompt` endpoint, including details on request parameters, example code snippets in multiple programming languages, and troubleshooting tips.
This comprehensive documentation provides all the necessary information to effectively use the `https://swarms.world/api/add-prompt`and `https://swarms.world/api/edit-prompt`endpoints, including details on request parameters, example code snippets in multiple programming languages, and troubleshooting tips.