Overview
The FacturaScripts API uses API key authentication. All API requests must include a valid API key in the request headers.API Key Types
There are two types of API keys:- Global API Key - Configured in the system configuration file, provides full access
- User API Keys - Created and managed through the admin panel, with granular permissions
Global API Key
The global API key is defined in your configuration file and provides unrestricted access to all API endpoints.User API Keys
User API keys are created in the FacturaScripts admin panel and can be configured with specific permissions for each resource and HTTP method.API Key Model
API keys are stored in theapi_keys table and managed through the ApiKey model (Core/Model/ApiKey.php).
API Key Properties
Unique identifier for the API key
The API key token (20 character random string)
Human-readable description of the API key
Username associated with the API key
Whether the API key is active
Whether the key has full access to all resources
Date when the API key was created
Timestamp of the last API request using this key
Creating an API Key
Through Admin Panel
- Navigate to Settings → API Keys
- Click New
- Enter a description for the key
- Choose whether to grant full access or configure specific permissions
- Save the API key
- Copy the generated API key token
API keys are automatically generated as 20-character random strings when created.
Programmatically
Configuring Permissions
Full Access
API keys withfullaccess = true can access all resources without restrictions.
Resource-Specific Access
For granular control, you can configure permissions per resource using theApiAccess model.
Permission Types
Allow GET requests (read access)
Allow POST requests (create access)
Allow PUT/PATCH requests (update access)
Allow DELETE requests (delete access)
Adding Resource Access
Checking Permissions
Making Authenticated Requests
Using X-Auth-Token Header
Include your API key in theX-Auth-Token header:
Alternative: Token Header
You can also use theToken header as an alternative:
JavaScript Example
Python Example
PHP Example
Authentication Errors
Invalid API Key
If the API key is invalid or missing:401 Unauthorized
Insufficient Permissions
If the API key doesn’t have permission for the requested resource/method:403 Forbidden
API Disabled
If the API is not enabled in your FacturaScripts installation:403 Forbidden
Security Best Practices
Use HTTPS
Use HTTPS
Always use HTTPS in production to encrypt API keys in transit.
Limit Permissions
Limit Permissions
Grant only the minimum necessary permissions to each API key. Avoid using
fullaccess unless absolutely required.Rotate Keys Regularly
Rotate Keys Regularly
Periodically generate new API keys and disable old ones.
Monitor Activity
Monitor Activity
Check the
lastactivity field to monitor API key usage and detect unauthorized access.Disable Unused Keys
Disable Unused Keys
Set
enabled = false for API keys that are no longer in use.Secure Storage
Secure Storage
Never commit API keys to version control. Use environment variables or secure configuration management.
Activity Tracking
FacturaScripts automatically tracks API key activity:Retrieving API Key Information
List All Access Rules
Get Access for Specific Resource
Testing Authentication
Test your API key by requesting the API root:Next Steps
Endpoints
Explore available API endpoints
Webhooks
Learn about webhook support

