> ## Documentation Index
> Fetch the complete documentation index at: https://exchanger-api.iexexchanger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Make your first Exchanger API request

> Check your exchanger's address, sign a private request with HMAC v2, read the route catalog, and request a quote without creating an order.

For your first Exchanger API request, ask the exchanger operator for their iEXExchanger installation domain. The installation serves the API at `/api/v3` on that domain. Check availability first, then verify your credentials and read the route catalog.

For a Go or PHP server application, you can start with a [server-side SDK](https://exchanger-api.iexexchanger.com/en/sdks.md).

## Check availability

Before making the request, replace `your-exchange` with your exchanger's domain.

```bash theme={null}
curl --fail-with-body --silent --show-error --max-time 15 \
  --header 'Accept: application/json' \
  'https://your-exchange/api/v3/ping'
```

The [public ping](https://exchanger-api.iexexchanger.com/en/api-reference/system/get-ping.md) returns HTTP `200`, `state: 0`, and `result.status: "ok"`. The `result.site_name` and `result.time` fields contain the exchanger name and server time. Keep `meta.request_id` if you need to report a problem to the operator.

## Make a signed request

Follow [API access](https://exchanger-api.iexexchanger.com/en/start/access.md) to get a Bearer token and its HMAC secret. Set these three variables in the Node.js process environment.

| Variable | Value |
| - | - |
| `EXCHANGER_API_ORIGIN` | Your exchanger's direct HTTPS origin, such as `https://your-exchange` |
| `EXCHANGER_API_TOKEN` | Bearer token |
| `EXCHANGER_API_HMAC_SECRET` | HMAC secret issued with that token |

Expand the example, copy the code to `request.mjs`, and run it with Node.js 24.

> [accordion] Source code for request.mjs
>
> ```javascript request.mjs theme={null}
> import { createHash, createHmac, randomBytes } from 'node:crypto';
> import { open } from 'node:fs/promises';
> import { basename } from 'node:path';
> import { parseArgs } from 'node:util';
>
> const usage = `Usage: node request.mjs [METHOD REQUEST_TARGET] [--json FILE | --file FILE --file-type TYPE] [--idempotency-key KEY]
> Default: GET /api/v3/private/ping
> Environment: EXCHANGER_API_ORIGIN, EXCHANGER_API_TOKEN, EXCHANGER_API_HMAC_SECRET`;
>
> function encodeComponent(value) {
>   return encodeURIComponent(value).replace(/[!'()*]/g, (character) =>
>     `%${character.charCodeAt(0).toString(16).toUpperCase()}`,
>   );
> }
>
> function canonicalQuery(search) {
>   if (!search) {
>     return '';
>   }
>
>   const entries = search.slice(1).split('&');
>   if (entries.length > 50) {
>     throw new Error('The example accepts at most 50 query fields.');
>   }
>
>   const names = [];
>   const pairs = [];
>   for (const entry of entries) {
>     const separator = entry.indexOf('=');
>     if (separator < 1 || entry.includes(';')) {
>       throw new Error('Use name=value query pairs separated by &. Encode a literal semicolon as %3B.');
>     }
>
>     const name = decodeURIComponent(entry.slice(0, separator).replaceAll('+', ' '));
>     const value = decodeURIComponent(entry.slice(separator + 1).replaceAll('+', ' '));
>     if (!/^[A-Za-z0-9_-]+(?:\[[A-Za-z0-9_-]+\]){0,6}$/.test(name)) {
>       throw new Error('Use query names such as filter[status_id][0], with explicit indexes for lists.');
>     }
>     if (names.some((previous) => name === previous || name.startsWith(`${previous}[`) || previous.startsWith(`${name}[`))) {
>       throw new Error('Give each query field a unique name and avoid scalar and nested forms of the same name.');
>     }
>
>     names.push(name);
>     pairs.push(`${encodeComponent(name)}=${encodeComponent(value)}`);
>   }
>
>   return pairs.sort().join('&');
> }
>
> async function readRequestFile(filename, limit, sizeLabel) {
>   const file = await open(filename, 'r');
>   try {
>     const stat = await file.stat();
>     if (!stat.isFile() || stat.size < 1 || stat.size > limit) {
>       throw new Error(`Use a nonempty local file of at most ${sizeLabel}.`);
>     }
>
>     const buffer = Buffer.alloc(stat.size + 1);
>     const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
>     if (bytesRead !== stat.size) {
>       throw new Error('Could not read the file at its original size.');
>     }
>
>     return buffer.subarray(0, bytesRead);
>   } finally {
>     await file.close();
>   }
> }
>
> async function jsonBytes(filename) {
>   const bytes = await readRequestFile(filename, 1_048_576, '1 MiB');
>   try {
>     JSON.parse(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes));
>   } catch {
>     throw new Error('Use a valid UTF-8 JSON file without a byte order mark.');
>   }
>
>   return bytes;
> }
>
> async function request() {
>   const { values, positionals } = parseArgs({
>     allowPositionals: true,
>     options: {
>       json: { type: 'string' },
>       file: { type: 'string' },
>       'file-type': { type: 'string' },
>       'idempotency-key': { type: 'string' },
>       help: { type: 'boolean' },
>     },
>   });
>   if (values.help) {
>     console.error(usage);
>     return;
>   }
>   if (positionals.length !== 0 && positionals.length !== 2) {
>     throw new Error(usage);
>   }
>
>   const [method = 'GET', target = '/api/v3/private/ping'] = positionals;
>   if (!['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
>     throw new Error('Use an uppercase GET, POST, PUT, PATCH, or DELETE method.');
>   }
>   const hasJson = values.json !== undefined;
>   const hasFile = values.file !== undefined;
>   const fileType = values['file-type'];
>   if (hasJson && hasFile) {
>     throw new Error('Choose either --json or --file.');
>   }
>   if (method === 'GET' && hasJson) {
>     throw new Error('Use --json only with a method that supports a request body.');
>   }
>   if (hasFile && (method !== 'POST' || !fileType || !/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(fileType))) {
>     throw new Error('Use --file with POST and set --file-type, for example application/pdf.');
>   }
>   if (!hasFile && fileType !== undefined) {
>     throw new Error('Use --file-type together with --file.');
>   }
>
>   const { EXCHANGER_API_ORIGIN: address, EXCHANGER_API_TOKEN: token, EXCHANGER_API_HMAC_SECRET: secret } = process.env;
>   if (!address || !token || !secret || !/^[!-~]+$/.test(token)) {
>     throw new Error('Set EXCHANGER_API_ORIGIN, EXCHANGER_API_TOKEN, and EXCHANGER_API_HMAC_SECRET.');
>   }
>   const origin = new URL(address);
>   if (origin.protocol !== 'https:' || origin.href !== `${origin.origin}/`) {
>     throw new Error('Use the direct HTTPS origin of your exchanger, without a path, credentials, or parameters.');
>   }
>   if (!target.startsWith('/api/v3/private/') || /[\u0000-\u0020\u007f#\\]/.test(target)) {
>     throw new Error('Use an origin-relative /api/v3/private/ path with an optional percent-encoded query.');
>   }
>   const url = new URL(target, origin);
>   if (url.pathname !== target.split('?', 1)[0] || url.pathname.includes('//')) {
>     throw new Error('Use the exact API path without relative segments or repeated slashes.');
>   }
>
>   const query = canonicalQuery(url.search);
>   const suppliedKey = values['idempotency-key'];
>   const key = suppliedKey?.trim() ?? '';
>   if (suppliedKey !== undefined && !/^[A-Za-z0-9._:-]{8,191}$/.test(key)) {
>     throw new Error('Use an idempotency key of 8 to 191 characters from A-Z, a-z, 0-9, dot, underscore, colon, and hyphen.');
>   }
>
>   let body;
>   let bytesToSign = '';
>   if (hasJson) {
>     bytesToSign = await jsonBytes(values.json);
>     body = bytesToSign;
>   } else if (hasFile) {
>     bytesToSign = await readRequestFile(values.file, 10_485_760, '10 MiB');
>     body = new FormData();
>     body.append('file', new Blob([bytesToSign], { type: fileType }), basename(values.file));
>   }
>
>   const bodyHash = createHash('sha256').update(bytesToSign).digest('hex');
>   const timestamp = String(Math.floor(Date.now() / 1000));
>   const nonce = randomBytes(16).toString('hex');
>   const canonical = ['v2', method, url.pathname, query, bodyHash, timestamp, nonce, key].join('\n');
>   const signature = createHmac('sha256', secret).update(canonical).digest('hex');
>
>   const headers = new Headers({
>     Accept: 'application/json',
>     Authorization: `Bearer ${token}`,
>     'X-Api-Signature-Version': 'v2',
>     'X-Api-Timestamp': timestamp,
>     'X-Api-Nonce': nonce,
>     'X-Api-Signature': `sha256=${signature}`,
>   });
>   if (hasJson) {
>     headers.set('Content-Type', 'application/json');
>   }
>   if (key !== '') {
>     headers.set('Idempotency-Key', key);
>   }
>
>   const response = await fetch(url, { method, headers, body, redirect: 'error', signal: AbortSignal.timeout(10_000) });
>   const responseBody = Buffer.from(await response.arrayBuffer());
>   process.stdout.write(responseBody);
>   console.error(`HTTP ${response.status}`);
>   let envelope;
>   try {
>     envelope = JSON.parse(responseBody.toString('utf-8'));
>   } catch {
>     throw new Error('Expected a JSON response from Exchanger API.');
>   }
>   if (!response.ok || envelope?.state !== 0) {
>     process.exitCode = 1;
>   }
> }
>
> try {
>   await request();
> } catch (error) {
>   console.error(error.message);
>   process.exitCode = 1;
> }
> ```

```bash theme={null}
node request.mjs
```

The command sends a signed [private ping](https://exchanger-api.iexexchanger.com/en/api-reference/system/get-private-ping.md). It checks the token and signature without requiring an additional scope. Expect HTTP `200` and JSON with `result.status: "ok"`. For a `401` response, read `error.code` and check your credentials, server time, and the [signing rules](https://exchanger-api.iexexchanger.com/en/start/authentication.md).

## Read the catalog and request a quote

Reading exchange routes requires `public-api:exchange:routes:read`.

```bash theme={null}
node request.mjs GET '/api/v3/private/exchange/routes?per_page=5'
```

Requesting a quote requires `public-api:exchange:quotes:read`. Save `route_id` and `amount` in `quote.json`. Replace `25` with an ID from your catalog and choose an amount within the limits for that route.

```json quote.json theme={null}
{"route_id": 25, "amount": "100.00"}
```

```bash theme={null}
node request.mjs POST /api/v3/private/exchange/quotes --json quote.json > quote-response.json
```

Read `result.quote` and retain `result.snapshot`. To check order data, send it with the snapshot to `POST /api/v3/private/exchange/orders/preflight` and inspect `result.preflight.can_create_order`, field errors, and verification requirements. If the operator enabled sandbox and granted its scope, use `POST /api/v3/private/sandbox/exchange/orders/simulate`. The simulation records an `api.sandbox.simulated` event without creating an order.

## request.mjs options

* Pass an uppercase method and a path starting with `/api/v3/private/`. The script accepts GET, POST, PUT, PATCH, and DELETE. Check the [API reference](https://exchanger-api.iexexchanger.com/en/api.md) for each operation's method and scopes.
* Write query parameters as `name=value` pairs, such as `filter[status_id][0]=7`. Use explicit indexes for lists. The example accepts up to 50 fields with ASCII letters, digits, underscores, and hyphens in their names, and up to six nested keys. Give each field a unique name. Percent-encode spaces and special characters in values.
* `--json FILE` accepts UTF-8 JSON without a BOM up to 1 MiB. The script signs and sends the original file bytes.
* Use `--file FILE --file-type TYPE` for a `POST` upload. The script hashes the file bytes and sends one multipart field named `file`. The example reads up to 10 MiB. Check the operation-specific limit and file types in the [file upload guide](https://exchanger-api.iexexchanger.com/en/guides/exchange/files-and-verifications.md).
* Pass the stored `--idempotency-key KEY` for operations that use that header. Keep the same key and data for a retry. Each invocation uses the current time and a new nonce, waits up to 10 seconds, and rejects redirects.
* Stdout contains the original response body, and stderr contains the HTTP status and diagnostics. The script exits with a nonzero status on failure. Responses may contain sensitive data, so keep saved response files in a protected directory.

## Next steps

* [Exchange flow](https://exchanger-api.iexexchanger.com/en/guides/exchange/overview.md)
* [Idempotency](https://exchanger-api.iexexchanger.com/en/guides/reliability/idempotency.md)
* [API errors](https://exchanger-api.iexexchanger.com/en/guides/reliability/errors.md)

> [accordion] Ask AI for help with the first request
>
> ```text theme={null}
> Prepare the first Exchanger API v3 request for my project.
> My stack is [STACK]. If it is unspecified, use the existing server stack
> or Node.js 24 for a standalone example.
>
> Verify the URL, signing headers and response format against these guides.
> https://exchanger-api.iexexchanger.com/en/start/quickstart
> https://exchanger-api.iexexchanger.com/en/start/authentication
>
> Provide two modes. GET /api/v3/ping checks the API address without credentials.
> GET /api/v3/private/ping checks the token and HMAC v2 without another scope.
> Read EXCHANGER_API_ORIGIN, EXCHANGER_API_TOKEN and EXCHANGER_API_HMAC_SECRET
> from the environment. Use https://your-exchange in examples.
> Add a timeout and check the HTTP status, state and result.status. On an error,
> report only the HTTP status, error.code and meta.request_id when available.
>
> Provide runnable code, commands and expected output.
> Verify the HMAC test vector and the 200 and 401 cases locally.
> Use fixtures and a local HTTP mock. Leave requests to a live exchanger to the
> operator and keep real tokens and secrets out of the conversation.
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.