strapi-plugin-api-select
v1.0.1
Published
A powerful Strapi v5 plugin that provides API-driven select fields with support for GET/POST requests, custom headers, flexible response mapping, and multilingual content.
Downloads
5
Maintainers
Readme
Strapi Plugin API Select
A powerful Strapi v5 plugin that provides API-driven select fields with support for GET/POST requests, custom headers, flexible response mapping, and multilingual content.
✨ Features
- 🔗 External API Integration - Fetch select options from any REST API
- 📡 HTTP Methods - Support for both GET and POST requests
- 🔐 Authentication - Custom headers and API token support
- 📋 Request Payloads - Configure JSON payloads for POST requests
- 🗺️ Flexible Mapping - Handle diverse API response structures
- 🌐 Proxy Mode - Built-in proxy for private APIs and CORS bypass
- 🌍 Multilingual - Works with Strapi's i18n features
- 📱 Selection Modes - Single or multiple selection
- ⚡ Performance - Optimized with error handling and caching
🚀 Installation
npm install strapi-plugin-api-select⚙️ Configuration
Add the plugin to your config/plugins.js file:
module.exports = {
// ...
"api-select": {
enabled: true,
},
// ...
};📖 Usage
1. Add Field to Content Type
- Go to Content-Type Builder in your Strapi admin
- Select your content type (e.g., Article, Product)
- Click Add another field
- Choose Custom → API Select
- Configure your field options
2. Field Configuration
Basic Settings
- Options API URL: The endpoint that returns your options
- Label Key: Field to use for display text (default:
name) - Value Key: Field to use for stored value (default:
id) - Select Mode: Single or Multiple selection
- Auth Mode: Public API or Proxy for private APIs
Advanced Settings
- HTTP Method: GET or POST (default:
GET) - Request Payload: JSON payload for POST requests
- Custom Headers: Additional headers as JSON object
- Response Data Path: Path to array in response (e.g.,
data,results) - Response Mapping: Custom field mapping for complex responses
📋 Examples
Basic GET Request
// API URL: https://api.example.com/categories
// Response:
[
{ id: 1, name: "Technology" },
{ id: 2, name: "Science" },
];
// Configuration:
// - Label Key: name
// - Value Key: idPOST Request with Payload
// Configuration:
// - HTTP Method: POST
// - Request Payload:
{
"filters": {"status": "active"},
"limit": 100
}
// - Custom Headers:
{
"Authorization": "Bearer your-token",
"X-API-Key": "your-api-key"
}Complex Response Mapping
// API Response:
{
"success": true,
"data": {
"users": [
{
"userId": 1,
"profile": {"displayName": "John Doe"},
"department": {"name": "Engineering"}
}
]
}
}
// Configuration:
// - Response Data Path: data.users
// - Response Mapping:
{
"value": "userId",
"label": "profile.displayName",
"group": "department.name"
}Different Response Formats
The plugin automatically handles various API response structures:
Direct Array
[
{ "id": 1, "name": "Option 1" },
{ "id": 2, "name": "Option 2" }
]Nested Data
{
"data": [
{ "id": 1, "title": "Option 1" },
{ "id": 2, "title": "Option 2" }
]
}Complex Structure
{
"response": {
"items": [{ "uuid": "abc-123", "label": "Custom Option" }]
}
}🔒 Security Features
- SSRF Protection: Validates API URLs to prevent server-side request forgery
- Proxy Mode: Routes requests through Strapi backend for private APIs
- Environment Variables: Support for API tokens via environment variables
Set your API token:
CUSTOM_STRAPI_SELECT_TOKEN=your_api_token_here🌐 Proxy Mode
For private APIs or to bypass CORS issues, use proxy mode:
- Set Auth Mode to "Proxy"
- Requests will be routed through your Strapi backend
- Configure authentication via environment variables
🎛️ Field Types Supported
Single Selection
Returns a single value:
"selected_option_id";Multiple Selection
Returns an array of values:
["option_1", "option_2", "option_3"];🔧 Development
Local Development
- Clone the repository
- Install dependencies:
npm install - Link locally:
npm link - In your Strapi project:
npm link strapi-plugin-api-select - Restart Strapi
Testing
npm test📄 API Reference
Server Routes
GET /api/api-select/fetch- Proxy endpoint for fetching external API data
Query Parameters
api- External API URLlabelKey- Field name for option labelsvalueKey- Field name for option valuesmethod- HTTP method (GET/POST)payload- JSON payload for POST requestsheaders- Custom headers as JSON string
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
📝 Changelog
See CHANGELOG.md for a list of changes.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🆘 Support
- 📖 Documentation
- 🐛 Issue Tracker
- 💬 Strapi Discord - Ask in #plugins channel
🙏 Acknowledgments
- Built for Strapi v5
- Inspired by the need for dynamic content in headless CMS
- Thanks to the Strapi community for feedback and contributions
Made with ❤️ for the Strapi community
