Which authentication headers do I send with API requests?

Authentication is how our API knows that a request really comes from your account. Every request must include your API key, be sent over HTTPS, and come from an IP address on your whitelist. If any of these are missing or wrong, the request is rejected before it reaches the service. This article explains the headers you send and how to avoid the most common mistakes.

The headers every request needs

HeaderPurposeExample value
AuthorizationCarries your API key as a bearer tokenBearer YOUR_API_KEY
AcceptAsks for a JSON responseapplication/json
Content-TypeTells us the body is JSON (for POST requests)application/json

Some services also accept an optional request ID header that you generate, which helps both sides trace a single call in logs. The API documentation lists any additional headers for each service.

Example request

curl -X POST "https://www.pepploweb.com/api/services/v1/recharge/mobile" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"number":"98XXXXXX10","operator":"OPERATOR_CODE","amount":"199","reference_id":"ORD10045"}'

The same request in PHP

$ch = curl_init('https://www.pepploweb.com/api/services/v1/recharge/mobile');
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . getenv('PEPPLO_API_KEY'),
    'Accept: application/json',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_TIMEOUT => 60,
]);
$response = curl_exec($ch);

Notice that the key is read from an environment variable rather than written into the code. This keeps it out of your source files and version control.

Rules for using your key

  • Server side only. Never put the key in a mobile app, browser JavaScript or a public repository. Anyone who extracts it could spend your wallet balance. Your app should call your own server, and your server calls our API.
  • HTTPS only. Plain HTTP requests are refused.
  • One key per environment. Use the test key on development and staging, and the live key only on production.
  • Rotate when people leave. If a developer who knew the key leaves the project, generate a new key and revoke the old one.

Common authentication mistakes

  • Missing "Bearer " before the key, or an extra space or line break copied with it.
  • Using a test key on live endpoints or the other way round. See our article on test and live keys.
  • Calling from a new server whose IP has not been whitelisted yet.
  • Proxies or frameworks stripping the Authorization header. Some server configurations do not pass this header to PHP. If logs show the header is missing on arrival, ask your host or check your web server configuration.
  • Revoked key still in a forgotten configuration file.

What the error responses mean

A 401 Unauthorized response means the key is missing, wrong or revoked. A 403 Forbidden response usually means the key is valid but the request is not allowed, for example because the IP is not whitelisted or the service is not enabled for your account. The response body includes an error code that tells you which.

The examples in this article are simplified to show the flow. Field names, endpoint paths and response formats can differ by service, so always follow the current reference in our API documentation.

Next steps

Manage keys and whitelisted IPs in your client area under the API section. If authentication still fails, open a ticket with the time of the request, the endpoint and the error code returned, but never the key itself.

Was this article helpful?

Still stuck? Open a support ticket and our team will help.


Related articles

← Back

Chat with us
Hi! Send us a message and we will reply here as soon as we can.
Security check image
Chat with us