Trading 212 API Update šŸ› ļø

I’m integrating the Trading 212 API into a Next.js app using HTTP Basic Authentication. Fresh ISA API credentials are being rejected with ā€˜Invalid API key’ error, even though the key shows as Active in my account settings. Here’s my implementation…"

  1. code structure (without credentials):

typescript

   function getBasicAuthHeader(): string {
       const apiKey = process.env.TRADING212_API_KEY;
       const secretKey = process.env.TRADING212_SECRET_KEY;
       const credentials = `${apiKey}:${secretKey}`;
       const encodedCredentials = Buffer.from(credentials).toString('base64');
       return `Basic ${encodedCredentials}`;
   }
  1. The curl command I’m using (with redacted credentials):

bash

   curl -X GET "https://live.trading212.com/api/v0/equity/account/cash" \
     -H "Authorization: Basic [BASE64_ENCODED_CREDENTIALS]"
  1. The error response:

json

   {"code":"UNAUTHENTICATED","message":"Invalid API key."}

Any ideas on how to move this forward?