Capital.com API POST /api/v1/session
Log in with your API key, login identifier and API key password. The CST and X-SECURITY-TOKEN tokens come back in the response headers.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
Confirmed on the official reference. Limited to 1 request per second per API key. Tokens stay valid for 10 minutes after last use. You need 2FA switched on before you can generate an API key. Method, path and request parameters were re-read on open-api.capital.com on 12 Oct 2026 and agree with this record; the mock reply was not compared field by field.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| identifierrequired | body | string | Your Capital.com login identifier. Placeholder only: never enter it on this site. |
| passwordrequired | body | string | The custom password you set for the API key. Placeholder only: never enter it on this site. |
| encryptedPassword | body | boolean | True only if you encrypted the password with the key from GET /api/v1/session/encryptionKey. Default false. |
Authentication headers
| Name | Type | Description |
|---|---|---|
| X-CAP-API-KEYrequired | string | Your API key from Settings > API integrations. Placeholder only: never paste a real key into this site. |
Request
Written from the method, path and parameters recorded on this page, against the demo host. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.
This call takes a request body. The samples send it as JSON with a Content-Type of application/json (in Python, passing json= sets that header) and a placeholder for each of the 2 body fields the record marks as required. Each placeholder has to be replaced with a real value before the request can succeed.
Python
# Set CAPITAL_API_KEY, CAPITAL_IDENTIFIER, CAPITAL_PASSWORD as environment variables first. Never paste real values into code.
# Optional and not shown: body fields encryptedPassword.
import os
import requests
BASE_URL = "https://demo-api-capital.backend-capital.com" # the demo host
headers = {
"X-CAP-API-KEY": os.environ["CAPITAL_API_KEY"],
}
body = {"identifier": os.environ["CAPITAL_IDENTIFIER"], "password": os.environ["CAPITAL_PASSWORD"]}
resp = requests.post(BASE_URL + "/api/v1/session", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set CAPITAL_API_KEY, CAPITAL_IDENTIFIER, CAPITAL_PASSWORD as environment variables first. Never paste real values into code.
// Optional and not shown: body fields encryptedPassword.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = "https://demo-api-capital.backend-capital.com"; // the demo host
const res = await fetch(BASE_URL + "/api/v1/session", {
method: "POST",
headers: {
"X-CAP-API-KEY": process.env.CAPITAL_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({"identifier": process.env.CAPITAL_IDENTIFIER, "password": process.env.CAPITAL_PASSWORD}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set CAPITAL_API_KEY, CAPITAL_IDENTIFIER, CAPITAL_PASSWORD as environment variables first. Never paste real values into code.
# Optional and not shown: body fields encryptedPassword.
curl -X POST "https://demo-api-capital.backend-capital.com/api/v1/session" \
-H "X-CAP-API-KEY: $CAPITAL_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"identifier\": \"$CAPITAL_IDENTIFIER\", \"password\": \"$CAPITAL_PASSWORD\"}"Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"accountType": "CFD",
"accountInfo": {
"balance": 1000,
"deposit": 1000,
"profitLoss": 0,
"available": 1000
},
"currencyIsoCode": "USD",
"currencySymbol": "$",
"currentAccountId": "MOCK-ACCOUNT-001",
"streamingHost": "wss://api-streaming-capital.backend-capital.com/",
"accounts": [
{
"accountId": "MOCK-ACCOUNT-001",
"accountName": "Mock USD",
"preferred": true,
"accountType": "CFD"
}
],
"clientId": "MOCK-CLIENT-01",
"timezoneOffset": 1,
"hasActiveDemoAccounts": true,
"hasActiveLiveAccounts": false,
"trailingStopsEnabled": false
}Response schema, HTTP 200
Every field this site's OpenAPI file for Capital.com declares for this response.
| Field | Type | Description |
|---|---|---|
| accountType | string | Not recorded |
| accountInfo | object | Not recorded |
| balance | number | Not recorded |
| deposit | number | Not recorded |
| profitLoss | number | Not recorded |
| available | number | Not recorded |
| currencyIsoCode | string | Not recorded |
| currencySymbol | string | Not recorded |
| currentAccountId | string | Not recorded |
| streamingHost | string | Not recorded |
| accounts | array of objects | Not recorded |
| accountId | string | Not recorded |
| accountName | string | Not recorded |
| preferred | boolean | Not recorded |
| accountType | string | Not recorded |
| clientId | string | Not recorded |
| timezoneOffset | integer | Not recorded |
| hasActiveDemoAccounts | boolean | Not recorded |
| hasActiveLiveAccounts | boolean | Not recorded |
| trailingStopsEnabled | boolean | Not recorded |
Unverifiedno source opened This schema is not sourced to a page of the provider's own that we opened, so check field names against the official reference.
Limits that apply at Capital.com
| Limit | Value | Scope | Source |
|---|---|---|---|
| Headline limit | 10/s per user | user | open-api.capital.comchecked |
Capital.com API errors you may meet
- error.null.api.keyHTTP 400. X-CAP-API-KEY header missing.
- error.account.limit.reachedHTTP 400. The demo account's balance cap has been reached, so it cannot be topped up further.
- error.invalid.accountHTTP 400. The account selected for a demo balance top up is not valid.
- error.invalid.accountIdHTTP 400. The account id sent when switching the active account is not valid.
- error.invalid.amountHTTP 400. The amount in a demo balance top up request is not valid.
- error.invalid.detailsHTTP 401. Invalid credentials on session creation.
All Capital.com API error codes, including 18 more not listed here.