Skip to main content

Best Practices

Follow these guidelines to build secure, reliable, and compliant applications on the Sri Lanka DPI Developer Portal.


๐Ÿ”’ Secure Your API Keysโ€‹

Never commit API keys to version control. Use environment variables and a secrets manager (e.g., HashiCorp Vault, AWS Secrets Manager). Rotate your key immediately if you suspect it has been compromised.

# โœ… Store in environment variables
export DPI_API_KEY="your-key-here"

# โŒ Never hardcode in source code
const apiKey = "sk-live-abc123...";

โฑ๏ธ Respect Rate Limitsโ€‹

Implement exponential back-off and respect the rate limits returned in response headers. Exceeding limits may temporarily suspend your sandbox access.

Retry-After: 30
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 0

๐Ÿ“Œ Version Your Integrationsโ€‹

Always pin to a specific API version in your integration. Subscribe to the Changelog โ†’ to be notified of breaking changes before upgrading.

# โœ… Pin to a specific version
GET /v1/apis/{apiId}/versions/2.0.0/endpoints

# โŒ Avoid using 'latest' in production
GET /v1/apis/{apiId}/versions/latest/endpoints

๐Ÿงช Use the Sandbox Firstโ€‹

Always validate your integration in the sandbox environment before requesting production access. Test all edge cases including error responses, rate limit handling, consent flows, and 404s โ€” use the Test Scenarios Panel to cover them systematically.


โœ… Complete Compliance Checklistsโ€‹

Ensure each application completes the Security Checklist and Privacy Checklist before going live. Incomplete compliance items will block your production approval.


๐Ÿšจ Handle Errors Gracefullyโ€‹

Implement proper error handling for all API calls. Display user-friendly messages and log technical details server-side โ€” never expose raw API errors or stack traces to end users.

HTTP CodeMeaningRecommended action
401Token expired or missingRefresh token and retry
403Insufficient scopeCheck your OAuth scopes
422Invalid request bodyValidate against OpenAPI schema
429Rate limit exceededBack off and retry after Retry-After
5xxPlatform errorCheck Platform Status, retry with back-off