Using Feature Layer from ArcGIS Online in ArcGIS Javascript

02-13-2019 03:59 PM
Regular Contributor

I'm playing around with the Javascript API for ArcGIS and wanted to use a feature layer from my Enterprise ArcGIS Online account. The script is quite simple, basically, create a map and add the feature layer. When I launch the webpage, the base map is populated and then I get a prompt to log into ArcGIS (see image below). I enter my enterprise credentials and it it tells me they are incorrect. My assumption is, that it's looking for credentials for a regular ArcGIS Online account ( as opposed to my enterprise account. So, my question is, how would I configure my Javascript to prompt me to log into my enterprise account. For reference, here is my code:

<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Intro to FeatureLayer - 4.10</title>

  <link rel="stylesheet" href="">
  <script src=""></script>

    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;

        Map, MapView,
      ) {

        var map = new Map({
          basemap: "hybrid"

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100

         * Add feature layer

        // Sample Feature Layers
        var featureLayer = new FeatureLayer({
          url: ""



  <div id="viewDiv"></div>


0 Kudos
5 Replies
MVP Esteemed Contributor


  The url you are using is Server6 from ESRI so you will have to use an AGOL login account. If the url was from your own on premise Portal the you could use your enterprise Portal account.

Regular Contributor

Thanks for the response Robert. Regardless of the Server6 portion of the URL, we use an enterprise login to access our AGOL account. My enterprise account is where that layer is being hosted. When I enter my enterprise login credentials, it does not accept them so I need to find out how to make that happen.

0 Kudos
MVP Esteemed Contributor


   I am not familiar with this enterprise account login that you are referring to. So I will bow out and let someone familiar with this chime in.

0 Kudos
Regular Contributor

Fair enough. For your reference, when you go to sign into AGOL on the sign in page ( ), there is a button at the bottom to log into an enterprise account as opposed to a personal account (along with the ability to sign in using Facebook or Google). The enterprise log in redirects you to to your organizational account.

Frequent Contributor II

Other than needing to log in, your URL is to the Service root (missing a layer id after FeatureServer/). FeatureLayers point to individual layers in the service, so maybe it should be