npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

strapi-plugin-api-select-field

v1.0.5

Published

A Strapi plugin that adds a reusable and configurable custom field for dynamic API-based select options

Downloads

34

Readme

Strapi Plugin: API Select Field

A powerful and secure Strapi v4+ plugin that adds a reusable and configurable custom field to the Content-Type Builder. This plugin allows users to select options (single or multiple) dynamically fetched from external APIs, supporting both public and secure/private endpoints.

🎯 Features

  • Dynamic API Integration: Fetch options from any external API endpoint
  • Flexible Selection Modes: Support for both single and multiple selection
  • Secure Authentication: Backend proxy for private APIs with proper authentication
  • Configurable Field Mapping: Customize label and value keys from API responses
  • Search & Filtering: Built-in search functionality with debounced API calls
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Security First: SSRF protection, input sanitization, and secure proxy implementation
  • Production Ready: Follows Strapi plugin standards and best practices

🚀 Installation

Via npm

npm install strapi-plugin-api-select-field

Via yarn

yarn add strapi-plugin-api-select-field

Manual Installation

  1. Clone this repository into your Strapi project's plugins folder:
cd plugins
git clone https://github.com/yourusername/strapi-plugin-api-select-field.git
  1. Install dependencies:
cd strapi-plugin-api-select-field
npm install
  1. Rebuild your Strapi admin panel:
npm run build

📖 Usage

1. Content-Type Configuration

Add the custom field to your Content Types in the Strapi admin panel:

{
  "attributes": {
    "country": {
      "type": "customField",
      "customField": "plugin::api-select-field.api-select-field",
      "customFieldConfig": {
        "optionsApi": "https://restcountries.com/v3.1/all",
        "optionLabelKey": "name.common",
        "optionValueKey": "cca2",
        "selectMode": "single",
        "authMode": "public",
        "placeholder": "Select a country...",
        "description": "Choose a country from the list"
      }
    }
  }
}

2. Field Configuration Options

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | optionsApi | string | ✅ | - | URL of the API to fetch options from | | optionLabelKey | string | ❌ | name | Key in API response to use as display label | | optionValueKey | string | ❌ | id | Key in API response to use as value | | selectMode | enum | ❌ | single | single or multiple selection | | authMode | enum | ❌ | public | public or proxy authentication | | placeholder | string | ❌ | - | Placeholder text for the select field | | description | string | ❌ | - | Help text for the field |

3. Authentication Modes

Public Mode (authMode: "public")

  • Direct API calls from the frontend
  • Suitable for public APIs with CORS enabled
  • Faster response times
  • No backend proxy required

Proxy Mode (authMode: "proxy")

  • Secure backend proxy for private APIs
  • API keys and tokens stored securely in environment variables
  • Prevents exposure of sensitive credentials
  • Recommended for production use with private APIs

🔐 Security Features

SSRF Protection

  • URL validation and sanitization
  • Blocked localhost and private IP ranges
  • Protocol validation (HTTP/HTTPS only)

Secure Proxy Implementation

  • Admin-only access to proxy endpoints
  • Request logging and auditing
  • Input sanitization and validation
  • Environment variable-based configuration

Best Practices

  • Never expose API keys in frontend code
  • Use HTTPS for all API communications
  • Implement proper CORS policies
  • Regular security audits and updates

🌍 Environment Variables

For proxy mode, configure these environment variables:

# Proxy Configuration (optional)
HTTP_PROXY=true
HTTP_PROXY_HOST=proxy.example.com
HTTP_PROXY_PORT=8080
HTTP_PROXY_AUTH=true
HTTP_PROXY_USERNAME=username
HTTP_PROXY_PASSWORD=password

# API-specific tokens (store securely)
EXTERNAL_API_TOKEN=your_api_token_here

📝 Example Configurations

Public API Example (Countries)

{
  "optionsApi": "https://restcountries.com/v3.1/all",
  "optionLabelKey": "name.common",
  "optionValueKey": "cca2",
  "selectMode": "single",
  "authMode": "public",
  "placeholder": "Select a country..."
}

Private API Example (Users)

{
  "optionsApi": "https://api.example.com/users",
  "optionLabelKey": "fullName",
  "optionValueKey": "userId",
  "selectMode": "multiple",
  "authMode": "proxy",
  "placeholder": "Select users..."
}

Grouped Options Example

{
  "optionsApi": "https://api.example.com/categories",
  "optionLabelKey": "categoryName",
  "optionValueKey": "categoryId",
  "optionGroupKey": "groupName",
  "selectMode": "single",
  "authMode": "proxy"
}

🛠️ Development

Prerequisites

  • Node.js >= 16.0.0
  • Strapi v4+
  • npm or yarn

Local Development

  1. Clone the repository:
git clone https://github.com/yourusername/strapi-plugin-api-select-field.git
cd strapi-plugin-api-select-field
  1. Install dependencies:
npm install
  1. Link to your Strapi project:
npm link
cd /path/to/your/strapi/project
npm link strapi-plugin-api-select-field
  1. Build and start:
npm run build
npm run develop

Testing

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix

# Format code
npm run format

📦 Building for Production

# Build the plugin
npm run build

# The built files will be in the `dist` folder

🔧 Troubleshooting

Common Issues

  1. Field not appearing in Content-Type Builder

    • Ensure the plugin is properly installed and built
    • Check Strapi version compatibility
    • Verify plugin registration in config/plugins.js
  2. API calls failing

    • Check CORS settings for public APIs
    • Verify API endpoint accessibility
    • Check network connectivity and firewall settings
  3. Proxy mode not working

    • Ensure user has admin authentication
    • Check environment variable configuration
    • Verify proxy endpoint accessibility

Debug Mode

Enable debug logging by setting the log level in your Strapi configuration:

// config/logger.js
module.exports = {
  level: 'debug',
  // ... other config
};

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Strapi plugin development standards
  • Write comprehensive tests for new features
  • Update documentation for any changes
  • Follow the existing code style and conventions
  • Ensure all tests pass before submitting PR

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Strapi team for the excellent plugin architecture
  • Contributors and users of this plugin
  • Open source community for inspiration and feedback

📞 Support

🔄 Changelog

v1.0.0

  • Initial release
  • Support for single and multiple selection
  • Public and proxy authentication modes
  • Comprehensive security features
  • Full Strapi v4+ compatibility

Made with ❤️ for the Strapi community

This plugin follows OWASP security guidelines and is designed for production use in enterprise environments.