---
title: Upload source maps via API
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-pro-features/upload-source-maps-api
---

Our browser monitoring supports the uploading of [source maps](https://docs.newrelic.com/docs/new-relic-browser-source-maps), which are used to un-minify error stack traces on the [**Errors** page](https://docs.newrelic.com/docs/errors-inbox/browser-tab). This document explains how to use the API to upload source maps using the browser API.

## Prepare for using the source map API [#questions]

In order to upload source maps to browser via the API, you'll need:

-   A New Relic user key
-   The New Relic [application ID](https://docs.newrelic.com/docs/browser/new-relic-browser/installation-configuration/copy-browser-monitoring-license-key-app-id) for the deployed app
-   The full [JavaScript file URL](#what-url)
-   Optionally, if the JavaScript URL doesn't automatically have release info appended to it, the [release name and ID](#release-id)

**What is the JavaScript URL?**

Every time the agent captures an error in your code, it's associated with the URL of the JavaScript in which it occurred. This is the `src` attribute of the script tag in your HTML. This full JavaScript URL is required when sending source maps to browser.

You can find the URL for an error's JavaScript file in browser, on the **JS errors** page. See [Browser monitoring source maps](https://docs.newrelic.com/docs/new-relic-browser-source-maps) for more on finding these errors in the UI.

**Is a release name and ID required?**

Many organizations include a version number or hash in the JavaScript URL. This is generally added to "bust" caches to ensure your users get the most recent version of your code. This type of URL might look something like:

-   `https://example.com/assets/application-59.min.js`
-   `https://example.com/assets/bundle-d6d031.min.js`
-   `https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js`

    If your app's URLs automatically have the version info appended to it, the browser agent has everything it needs in order to match errors with your code. You can move ahead to [generating source maps](#generate).

    If this **doesn't** apply to you, and JS URLs do **not** have version info appended, you’ll have to assist the agent by specifying a [release name and ID with the API](https://docs.newrelic.com/docs/browser-api-newrelicaddrelease).

**Is a repo URL or a build commit hash required?**

If you're interested in monitoring the performance of your code from your IDE using New Relic CodeStream, repository URL is required. If you'd like to investigate errors from your IDE as well, the build commit hash is recommended, but not required.

Learn more about [monitoring performance](https://docs.newrelic.com/docs/codestream/how-use-codestream/performance-monitoring) by bringing observability into the IDE.

**Are there limits to source map uploads?**

There is no limit to the overall number of source maps you can upload. However, the API is rate-limited per account:

-   You can upload a maximum of 1000 source maps per minute.
-   Only one source map can be uploaded or published per API request.

    Source map files can be a maximum of 50Mb in size.

**Which application ID should be used?**

Both `YOUR_NEW_RELIC_APP_ID` and `YOUR_APP_ID` are valid values for `applicationId`.

## Push source maps to New Relic [#publish]

Now that you have one or more source maps, you are ready to publish it to browser. You can use any of these methods to send source maps to browser:

-   Use the [New Relic npm module](#npm) with the API via the command line or via a client-side JavaScript build/deploy script like Gulp or Grunt.
-   Use [API curl commands](#api).
-   Use the [browser UI](https://docs.newrelic.com/docs/new-relic-browser-source-maps).

## Use npm module via command line or client-side script [#npm]

The easiest and recommended way to upload source maps to browser is to use the our new [`@newrelic/publish-sourcemap` npm module](https://www.npmjs.com/package/@newrelic/publish-sourcemap). It provides a command line tool and Javascript API to accomplish this task. More documentation is available in the npm repo.

Here are some examples of using the npm module via the command line.

> #### ⚠️ IMPORTANT
>
> The following examples are for US accounts (default). For other regions, use the corresponding endpoint:
>
> -   EU accounts: `https://sourcemaps.service.eu.newrelic.com`
> -   JP accounts: `https://sourcemaps.service.jp.newrelic.com`
>
>     For more information, see [Choose your data center](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/choose-your-data-center).

**npm command line: Publish**

Here's an example of uploading source maps using the npm module via the command line. Note that the source map can come from a local file or a remote URL.

````bash
npm install -g @newrelic/publish-sourcemap
publish-sourcemap PATH_TO_SOURCE_MAP_FILE (local or remote) PATH_TO_ORIGINAL_FILE --apiKey=YOUR_NEW_RELIC_USER_KEY --applicationId=YOUR_NEW_RELIC_APP_ID --repoUrl=GITHUB_REPOSITORY_URL --buildCommit=GIT_BUILD_COMMIT_HASH
```

````

**npm command line: List published maps**

Here's an example of listing published source maps:

````bash
list-sourcemaps --applicationId=YOUR_APP_ID --apiKey=YOUR_NEW_RELIC_USER_KEY
[output]
[output] Options:
[output]   --applicationId  Browser application id
[output]   --apiKey         New Relic user API key
```

````

**npm command line: Delete**

Here's an example of deleting a source map:

````bash
delete-sourcemap --applicationId=YOUR_APP_ID --apiKey=YOUR_NEW_RELIC_USER_API_KEY --sourcemapId=YOUR_SOURCE_MAP_ID
[output] 
[output] Options:
[output]   --applicationId  Browser application id
[output]   --apiKey         New Relic user API key
[output]   --sourcemapId    Unique id generated for a source map
```

````

Here are some examples of using the npm module to publish from client-side JavaScript:

**npm via Node.js script: Publish**

Here's an example of publishing a source map via a Node.js script:

````js
var publishSourcemap = require('@newrelic/publish-sourcemap').publishSourcemap;

publishSourcemap({
  sourcemapPath: 'SOURCE_MAP_FULL_PATH',
  javascriptUrl: 'JS_URL',
  applicationId: YOUR_NEW_RELIC_APP_ID,
  apiKey: 'YOUR_NEW_RELIC_USER_API_KEY',
  repoUrl: 'GITHUB_REPOSITORY_URL',
  buildCommit: 'GIT_BUILD_COMMIT_HASH'
}, function(err) { console.log(err || 'Sourcemap upload done'); });
```

````

**npm via Node.js script: List published maps**

Here's an example of listing all published source maps:

````js
var listSourcemaps = require('@newrelic/publish-sourcemap').listSourcemaps;;

listSourcemaps({
  applicationId: YOUR_NEW_RELIC_APP_ID,
  apiKey: 'YOUR_NEW_RELIC_USER_API_KEY',
  limit: MAX_NUMBER_OF_RESULTS_TO_RETURN || 20,
  offset: NUMBER_OF_RESULTS_TO_SKIP_BEFORE_RETURNING || 0,
}, function(err, res) { console.log(err || res.sourcemaps); });
```

````

**npm via Node.js script: Delete**

Here's an example of deleting a source map file via a Node.js script:

````js
var deleteSourcemap = require('@newrelic/publish-sourcemap').deleteSourcemap;

deleteSourcemap({
  sourcemapId: 'SOURCE_MAP_ID',
  applicationId: YOUR_NEW_RELIC_APP_ID,
  apiKey: 'YOUR_NEW_RELIC_USER_API_KEY',
}, function(err) { console.log(err || 'Deleted source map'); });
```

````

When you're done, go to the [**JS errors** page](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-pro-features/javascript-errors-page-examining-errors-over-time) in browser, select an error grouping, and see if your error stack traces have been un-minified.

## Use API via curl [#api]

Below are some examples of using curl to publish, list, and delete source maps:

**curl: Upload maps**

An example of using API via curl to publish maps to browser:

````bash
curl -H "Api-Key: YOUR_NEW_RELIC_USER_API_KEY" \ 
     -F "sourcemap=@SOURCE_MAP_PATH" \ 
     -F "javascriptUrl=JS_URL" \ 
     -F "releaseId=YOUR_RELEASE_ID" \ 
     -F "releaseName=YOUR_UI_PAGE" \
     https://sourcemaps.service.newrelic.com/v2/applications/YOUR_NEW_RELIC_APP_ID/sourcemaps
```

```bash
curl -H "Api-Key: YOUR_NEW_RELIC_USER_API_KEY" \ 
     -F "sourcemap=@SOURCE_MAP_PATH" \ 
     -F "javascriptUrl=JS_URL" \ 
     -F "releaseId=YOUR_RELEASE_ID" \ 
     -F "releaseName=YOUR_UI_PAGE" \
     -F "repoUrl=GITHUB_REPOSITORY_URL" \
     -F "buildCommit=GIT_BUILD_COMMIT_HASH" \
     https://sourcemaps.service.newrelic.com/v2/applications/YOUR_NEW_RELIC_APP_ID/sourcemaps
```

````

**curl: List existing maps**

Below is an example of how to get a list of source maps previously uploaded to New Relic via curl. New Relic returns the source map's unique `SOURCEMAP_ID` and its components:

````bash
curl -H "Api-Key: YOUR_NEW_RELIC_USER_API_KEY" \ 
    https://sourcemaps.service.newrelic.com/v2/applications/YOUR_NEW_RELIC_APP_ID/sourcemaps
```
By default, `20` source maps are retrieved. To retrieve a different number of source maps, append `?limit=<NEW-LIMIT>` to the end of the URL, where `<NEW-LIMIT>` is your desired limit. You can retrieve up to `500` source maps at a time.



````

**curl: Delete map**

To delete a source map:

1.  Use the GET endpoint to list existing source maps and locate the `SOURCEMAP_ID`.
2.  Run the following command via curl:

    ```bash
    curl -X DELETE \
         -H "Api-Key: YOUR_NEW_RELIC_USER_API_KEY" \
         https://sourcemaps.service.newrelic.com/v2/applications/YOUR_NEW_RELIC_APP_ID/sourcemaps/SOURCEMAP_ID
    ```

When you're done, go to the [**Group errors** tab](https://docs.newrelic.com/docs/errors-inbox/browser-tab) in browser, select an error grouping, and see if your error stack traces have been un-minified.

## Troubleshoot source maps [#troubleshoot]

If you are having trouble generating source maps from your build system, or if your errors in browser remain minified, see the [source maps troubleshooting](https://docs.newrelic.com/docs/new-relic-browser-source-maps#troubleshoot) documentation.
