Authentication
API V2 uses the OAuth 2.0 client credentials flow: your application exchanges its client_id and client_secret for a short-lived access_token, and sends that token on every call.
Three different things
| Item | What it identifies | Where it is used |
|---|---|---|
| Ecovoy login (email + password) | You, the person | Only to sign in to ecovoy.com and this portal. Never send it to the API. |
client_id + client_secret | Your application, in one environment | Only on POST /oauth/token, from your server. |
access_token | A temporary authorization for your application | The Authorization: Bearer header of every API call. |
1. Getting client_id and client_secret
- Log in with your Ecovoy account.
- Go to Dashboard → My applications and open (or create) an application.
- Click Generate sandbox credentials. For Production, the application must first be approved by an Ecovoy administrator.
| Value | Sandbox prefix | Production prefix |
|---|---|---|
client_id | ecv_test_ | ecv_live_ |
client_secret | ecvs_test_ | ecvs_live_ |
access_token | ecvat_test_ | ecvat_live_ |
The client_secret is displayed only once, right after generation. Ecovoy stores only a hash of it and cannot show it again. Generating new credentials immediately revokes the previous pair and every token issued with it.
2. Requesting an access_token
POST https://api.ecovoy.com/api/v2/oauth/token — body as application/x-www-form-urlencoded or JSON.
| Parameter | Required | Description |
|---|---|---|
grant_type | Yes | Always client_credentials. |
client_id | Yes* | Your client ID. |
client_secret | Yes* | Your client secret. |
scope | No | Space-separated subset of your scopes. Omit it to receive every scope your account is entitled to. |
* Or send them with HTTP Basic authentication (client_id:client_secret).
# Alternative: HTTP Basic authentication (client_id:client_secret)
curl -X POST https://api.ecovoy.com/api/v2/oauth/token \
-u "$ECOVOY_CLIENT_ID:$ECOVOY_CLIENT_SECRET" \
-d grant_type=client_credentials \
-d "scope=balance:read topup:read"
<?php
$ch = curl_init('https://api.ecovoy.com/api/v2/oauth/token');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => getenv('ECOVOY_CLIENT_ID') . ':' . getenv('ECOVOY_CLIENT_SECRET'),
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'client_credentials',
'scope' => 'balance:read topup:read', // optional
]),
]);
$token = json_decode(curl_exec($ch), true);
const basic = Buffer.from(
`${process.env.ECOVOY_CLIENT_ID}:${process.env.ECOVOY_CLIENT_SECRET}`
).toString('base64');
const token = await fetch('https://api.ecovoy.com/api/v2/oauth/token', {
method: 'POST',
headers: {
Authorization: `Basic ${basic}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'client_credentials',
scope: 'balance:read topup:read', // optional
}),
}).then(r => r.json());
{
"access_token": "ecvat_test_9f2c...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "balance:read topup:read",
"environment": "sandbox"
}
Errors on this endpoint follow the OAuth 2.0 format ({"success": false, "error": "...", "error_description": "..."}). See Error codes.
3. Using the token
Send the token in the Authorization header. Never put credentials or tokens in URLs or query strings.
curl https://api.ecovoy.com/api/v2/balance \
-H "Authorization: Bearer $ECOVOY_ACCESS_TOKEN"
<?php
$ch = curl_init('https://api.ecovoy.com/api/v2/balance');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $accessToken],
]);
$balance = json_decode(curl_exec($ch), true);
const balance = await fetch('https://api.ecovoy.com/api/v2/balance', {
headers: { Authorization: `Bearer ${accessToken}` },
}).then(r => r.json());
The token alone determines the application, the owner account and the environment. The API never accepts organization_id, application_id or an environment from the request body.
4. Expiration
- Tokens are valid for 3600 seconds (60 minutes). The exact value is in
expires_in. - There is no refresh token: when a token expires, request a new one with your credentials.
- An expired, revoked or unknown token returns
401with"code": "INVALID_TOKEN". - Tokens also stop working immediately if the credentials are revoked or regenerated, if the application is suspended, or if Production approval is withdrawn.
- Reuse the same token for many calls; do not request one per call. The token endpoint is limited to 10 requests per minute per client.
<?php
// Reuse the token until shortly before it expires.
function ecovoyToken(): string
{
static $cached = null;
if ($cached && $cached['expires_at'] > time() + 60) {
return $cached['access_token'];
}
$ch = curl_init('https://api.ecovoy.com/api/v2/oauth/token');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'client_credentials',
'client_id' => getenv('ECOVOY_CLIENT_ID'),
'client_secret' => getenv('ECOVOY_CLIENT_SECRET'),
]),
]);
$t = json_decode(curl_exec($ch), true);
$cached = ['access_token' => $t['access_token'], 'expires_at' => time() + $t['expires_in']];
return $cached['access_token'];
}
let cached = null;
async function ecovoyToken() {
if (cached && cached.expiresAt > Date.now() + 60_000) return cached.accessToken;
const t = await fetch('https://api.ecovoy.com/api/v2/oauth/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.ECOVOY_CLIENT_ID,
client_secret: process.env.ECOVOY_CLIENT_SECRET,
}),
}).then(r => r.json());
cached = { accessToken: t.access_token, expiresAt: Date.now() + t.expires_in * 1000 };
return cached.accessToken;
}
5. Scopes and permissions
Scopes limit what a token can do. They follow the permissions your Ecovoy account already has: a token only receives the scopes your account is entitled to, and the permission is checked again on every call. If a permission is removed from your account, the related calls stop working right away.
| Scope | Allows |
|---|---|
account:read | Read the application and account context of the token. |
balance:read | Read the account balance. |
transactions:read | List and read transactions. |
topup:read | Look up mobile operators and top-up products. |
topup:write | Create mobile top-up orders. |
Calling an endpoint without the required scope returns 403 with "code": "INSUFFICIENT_SCOPE". Your application page in the dashboard shows which scopes your account currently has.
6. Environments
Sandbox
Test credentials (ecv_test_). Simulated responses and a simulated balance. No real operations, no charges, no providers called.
Production
Live credentials (ecv_live_), available only after manual approval by an Ecovoy administrator. Uses your real Ecovoy account and balance.
Security checklist
- Keep
client_secreton your server (environment variables or a secret manager). Never ship it in a mobile app, browser code or a public repository. - Do not log credentials or tokens.
- Use HTTPS only.
- If a secret leaks, revoke or regenerate it in the dashboard immediately.