Automating OAuth 2.0 Token Management
This guide shows you how to implement automated token management in your RABOT Partner API integration, ensuring your scripts maintain uninterrupted access without manual intervention.Token Lifecycle
Key Points:- Tokens expire after ~1 hour (3599 seconds)
- No refresh tokens - re-authenticate with client credentials when expired
- Proactive token renewal recommended (don’t wait for 401 errors)
Token Request
Use your client credentials to obtain an access token:replace CLIENT_ID and CLIENT_SECRET with the credentials you received from Rabot Charge. See Partner setup
Example API request
Scopes
You need to specify, which scopes you want to include in the token by specifying them inscope parameter.
Multiple Scopes: Separate multiple scopes with spaces, e.g.,
api:partner create:orders| Scope | Description |
|---|---|
api:partner | permission to access Partner API, required for all API requests |
create:orders | permission to create orders |
role:finance-reporting | permission to access customer and contract data, limited to finance reporting related information |
role:customer-support | permission to access customer and contract data, limited to customer support related information (includes role: finance-reporting) |
role:application | permission to access all customer and contract data (includes role: finance-reporting and role:customer-support ) |
| Scope | Description |
|---|---|
api:partner | permission to access Partner API, required for all API requests |
| Scope | Description |
|---|---|
api:partner | permission to access Partner API, required for all API requests |
create:orders | permission to create orders |
role:finance-reporting | permission to access customer and contract data, limited to finance reporting related information |
To use scopes, you need to have them assigned to your API client by RABOT administrators. If you feel you should have a scope, that you don’t have, please contact our Integration Management team.
Token Response
If successful, the authentication server responds with a HTTP/200 status code, and the response body contains a structure with the access tokenExample API request
Note that the token only has a limited life time; when the life time has expired, you will need to request a new token from the authentication server.
Best Practices
1. Proactive Token Renewal
Don’t wait for tokens to expire - renew them proactively:2. Secure Credential Storage
Recommended approaches:3. Error Handling
Always handle authentication errors gracefully:4. Logging (Without Exposing Secrets)
Log authentication events, but never log tokens or credentials:5. Thread Safety (For Multi-threaded Applications)
If your application uses multiple threads, protect token operations:Common Issues & Solutions
Issue 1: “Invalid client credentials”
Cause: Incorrectclient_id or client_secret
Solution:
- Verify credentials in your Partner setup
- Check for typos or extra whitespace
- Ensure you’re using the correct environment (staging vs. production)
Issue 2: “Insufficient scopes”
Cause: Requesting access to endpoints without the required scopes Solution:- Review available scopes for your partner type (Whitelabel, HEMS, Sales Affiliate)
- Contact Integration Management to request additional scopes
- Update your scope list in the authentication request
Issue 3: Frequent 401 errors
Cause: Token expiring between validation check and API request Solution:Issue 4: High authentication rate
Cause: Re-authenticating too frequently Solution:- Increase buffer time to avoid premature re-authentication
- Cache tokens in memory (don’t re-authenticate for every request)
- Check your expiry calculation logic
Testing Your Implementation
Manual Test
Testing Checklist
- Initial authentication works
- Token is used in API requests (Bearer header)
- Token expiry is calculated correctly
- Token is renewed before expiry (proactive)
- 401 errors trigger re-authentication
- Credentials are not hardcoded
- Credentials are not logged
- Error handling is robust
- Multi-threaded access is safe (if applicable)