How to extend the expires_in time in Admin API?
Extending API Timeouts in Shopware 6.6: A Developer's Guide
When developing with Shopware 6.6, you might encounter situations where the default API timeout settings are too restrictive, especially during development or when handling large data sets. This guide explains how to extend these timeouts and understand the available configuration options.
Configuration Parameters
The key configuration parameters can be set in your shopware.yaml
file:
shopware:
api:
max_limit: 2000
access_token_ttl: "PT12H"
store:
context_lifetime: "P7D"
Understanding the Parameters
- max_limit: Defines the maximum number of items that can be returned in a single API request
- access_token_ttl: Sets the lifetime of API access tokens
- context_lifetime: Determines how long the store context remains valid
ISO 8601 Duration Format
Shopware uses the ISO 8601 duration format for time specifications. Here's how to read and use these durations:
Common Duration Patterns
Format | Meaning | Example Use Case |
---|---|---|
P1Y | 1 year | Long-term tokens |
P1M | 1 month | Monthly maintenance windows |
P1D | 1 day | Daily operations |
P30D | 30 days | Monthly cache clearing |
PT1H | 1 hour | Short-term sessions |
PT5M | 5 minutes | Quick operations |
PT35S | 35 seconds | Brief transactions |
Combining Durations
You can combine these units for more precise timing. For example:
- P1Y6M (1 year and 6 months)
- P1DT12H (1 day and 12 hours)
- PT1H30M (1 hour and 30 minutes)
Best Practices
- Development Environment
- Use longer durations during development to avoid frequent token refreshes
- Consider setting
access_token_ttl: "P7D"
for week-long development sessions
- Production Environment
- Keep durations shorter for security
- Recommended:
access_token_ttl: "PT12H"
or less - Regular context refresh:
context_lifetime: "P1D"
- Performance Optimization
- Adjust
max_limit
based on your server capabilities - Consider pagination for large datasets
- Monitor API response times after changes
- Adjust
Implementation Example
For a development environment focusing on extended working sessions:
shopware:
api:
max_limit: 5000 # Increased for development
access_token_ttl: "P7D" # 7-day tokens
store:
context_lifetime: "P30D" # Monthly context refresh
Security Considerations
Remember that extending timeouts, especially in production:
- Increases the window of opportunity for token misuse
- May impact system resource usage
- Should be balanced against security requirements
Always review these settings before deploying to production and adjust according to your specific security needs and usage patterns.
Troubleshooting
If you experience issues after changing these settings:
- Clear your cache
- Regenerate access tokens
- Verify the syntax of your duration strings
- Check server logs for timeout-related errors
Remember to test thoroughly after any configuration changes to ensure your applications continue to function as expected.