Elad Benda Elad Benda - 2 years ago 320
HTML Question

Failed to load resource: the server responded with a status of 401 for mapbox api

I have followed leaflet "get started" tutorial

but I get an 401 error while trying to load the tiles

Failed to load resource: the server responded with a status of 401

what am I missing?

my html


<link rel="stylesheet" href="elad_map.css" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />

<div id="map"></div>

<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script type="text/javascript" src="elad_map.js"></script>


document.onload = loadMap();

function loadMap() {
var map = L.map('map').setView([51.505, -0.09], 13);

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'your.mapbox.project.id',
accessToken: 'your.mapbox.public.access.token'

var circle = L.circle([51.508, -0.11], 500, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5

var polygon = L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]


iH8 iH8
Answer Source

What forgot to swap out the id and accessToken:

id: 'your.mapbox.project.id',
accessToken: 'your.mapbox.public.access.token'

You'll need to change the accessToken to the one you get when registering with Mapbox and the id to a mapbox project id like mapbox.streets, mapbox-outdoors, mapbox-satellite or a custom id you get when creating a custom map via Mapbox Studio Classic.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download