# Source Map Stack Trace Resolver API

> Turn minified JavaScript stack traces into original files, lines, function names and code context with uploaded or auto-discovered source maps.

- Endpoint: `GET | POST https://apibox.io.vn/v1/source-map`
- Category: Developer utilities
- HTML docs: https://apibox.io.vn/docs/source-map/ (Vietnamese: https://apibox.io.vn/vi/docs/source-map/)
- Online tool: https://apibox.io.vn/tools/source-map/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Paste a stack trace from Chrome / Edge / Node (`at fn (file:line:col)`), Firefox / Safari (`fn@file:line:col`) or React Native / Hermes, plus the source map: `map` (JSON or a JS file with an inline `data:` sourceMappingURL), `maps` (an object `{"app.js.map": …}` for several bundles), `map_url`, or a `.map` / `.zip` of maps as a file. With `fetch=1` the service downloads each script URL in the trace, follows its `//# sourceMappingURL` comment or `SourceMap` header and fetches the map (public URLs only, size and redirect limits).

Each frame gets the original source, line, column, the original function name (taken from the caller's mapping, like error trackers do), `context` lines from `sourcesContent`, and a `library` flag for node_modules / ignore-listed sources; `resolved_stack` is the whole trace rewritten. Index maps (sections) and maps from Vite, webpack, esbuild, Rollup and Terser work. `action=lookup` maps one line / column (or the reverse with `source=`); `action=validate` checks a map: version, sources / sourcesContent consistency, mappings that decode and stay inside the source, ignoreList, debugId, and warns when the map exposes your source code.

Maps and code are processed in memory and never stored or logged. Uses source-map-js (BSD-3-Clause).

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `stack` | body | string | no |  | The stack trace (required for action=resolve; max 500 frames). |
| `map` | body | object | no |  | Source map (object or JSON text, or JS with an inline data: sourceMappingURL). |
| `maps` | body | object | no |  | Several maps keyed by script / map name or URL. |
| `file` | body | file | no |  | A .map file or a .zip of .map files. |
| `map_url` | body|query | string | no |  | URL of a source map to download. |
| `fetch` | body|query | boolean | no |  | `1`: discover maps from the script URLs in the trace (max 6 scripts). |
| `context` | body|query | number | no | `3` | Lines of code around each frame (0–10). |
| `action` | body|query | string | no |  | `resolve` (default with stack), `lookup` (line, column[, source]) or `validate` (optional `js` = generated code). |
| `line` | body|query | number | no |  | lookup: generated line (1-based), or original line with `source`. |
| `column` | body|query | number | no |  | lookup: column (1-based like stack traces; `column_base=0` for 0-based). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/source-map" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"stack":"Error: boom at 3\n    at n (https://example.com/assets/out.js:1:47)\n    at t (https://example.com/assets/out.js:1:122)\n    at u (https://example.com/assets/out.js:1:156)","map":{"version":3,"sources":["lib.ts","app.ts"],"sourcesContent":["export function helper(x: number): number {\n  if (x > 2) {\n    throw new Error('\''boom at '\'' + x);\n  }\n  return x * 2;\n}\n","import { helper } from '\''./lib'\'';\n\nfunction computeTotal(items: number[]): number {\n  let sum = 0;\n  for (const i of items) sum += helper(i);\n  return sum;\n}\n\nexport function main() {\n  return computeTotal([1, 2, 3]);\n}\nmain();\n"],"mappings":"mBAAO,SAASA,EAAOC,EAAmB,CACxC,GAAIA,EAAI,EACN,MAAM,IAAI,MAAM,WAAaA,CAAC,EAEhC,OAAOA,EAAI,CACb,CCHA,SAASC,EAAaC,EAAyB,CAC7C,IAAIC,EAAM,EACV,QAAWC,KAAKF,EAAOC,GAAOE,EAAOD,CAAC,EACtC,OAAOD,CACT,CAEO,SAASG,GAAO,CACrB,OAAOL,EAAa,CAAC,EAAG,EAAG,CAAC,CAAC,CAC/B,CACAK,EAAK","names":["helper","x","computeTotal","items","sum","i","helper","main"]},"context":1}'
```

## Example response

```json
{
  "message": "Error: boom at 3",
  "frames_total": 3,
  "frames_resolved": 3,
  "frames": [
    {
      "raw": "at n (https://example.com/assets/out.js:1:47)",
      "function": "n",
      "file": "https://example.com/assets/out.js",
      "line": 1,
      "column": 47,
      "original": {
        "source": "lib.ts",
        "line": 3,
        "column": 11,
        "function": "helper",
        "name": null
      },
      "library": false,
      "context": {
        "start_line": 2,
        "lines": [
          "  if (x > 2) {",
          "    throw new Error('boom at ' + x);",
          "  }"
        ],
        "highlight": 3
      },
      "map": "map"
    },
    {
      "raw": "at t (https://example.com/assets/out.js:1:122)",
      "function": "t",
      "file": "https://example.com/assets/out.js",
      "line": 1,
      "column": 122,
      "original": {
        "source": "app.ts",
        "line": 5,
        "column": 33,
        "function": "computeTotal",
        "name": "helper"
      },
      "library": false,
      "context": {
        "start_line": 4,
        "lines": [
          "  let sum = 0;",
          "  for (const i of items) sum += helper(i);",
          "  return sum;"
        ],
        "highlight": 5
      },
      "map": "map"
    },
    "…"
  ],
  "resolved_stack": "Error: boom at 3\n    at helper (lib.ts:3:11)\n    at computeTotal (app.ts:5:33)\n    at u (app.ts:10:10)"
}
```

## Use cases

- Read production JavaScript errors without paying for an error-tracking platform
- Let a support bot or n8n flow turn customer error logs into real file / line references
- Check in CI that deployed source maps match the bundle and do not leak sources
- Map a Hermes / React Native crash back to the original code

## FAQ

### Do you keep my source maps?

No. Maps, scripts and stack traces are processed in memory for that request only and are not stored or logged.

### Why is the function name taken from the next frame?

Minified frames carry the minified name; the original name is the identifier mapped at the call site in the calling frame, as Sentry and Chrome DevTools do.

### What if my map has no sourcesContent?

Frames still resolve to original file / line / column, but no code context can be shown; action=validate reports it.
