AnsweredAssumed Answered

How can I load a private layer giving the the App login data ?

Question asked by AmalkaNish on Jun 13, 2016
Latest reply on Jun 13, 2016 by AmalkaNish

Im trying to load a private feature layer using app login. I have my App ID and a generated token and I'm trying to feed that data to a credential object and load the feature layer. But when the layer get loaded it still askes for log in infomation even though I have them attacehd with the feature layer.


How can I load a feature layer providng my app login info so that it will not pop the login info dialog ? Please help


Find below the code I tired.


function layerLoad()


  require(["esri/request", "esri/layers/FeatureLayer", "esri/Credential"],

  function(esriRequest, FeatureLayer, Credential) {

     var layers = [];

     var featureLayer;

     var layerOptions;

     var token = "L7yIuZW-h9ODkLRHOpnWpYlxHzHVIUdUgKQQKHqPLOVrNHMYi3clvlCTF6V5Xw64Xor-TUsUtrmfKXnQ5iomxO6_ltRRGFpq-UlO01C4XnIN6wSxjtHp15ciXeUIsEEA3cknZKsFKA1IrE_P28zmug..";   

     var privateLayerUrl = "";


     var privateLayerWithToken = privateLayerUrl + "?token=" + token;


     var layersRequest = esriRequest({

       url: privateLayerWithToken,

       content: { f: "json" },

       //form:{ token: token },

       handleAs: "json",

       //callbackParamName: "callback"



  var credentials = new Credential({

  userId:"eR4g2n1Qv1U18Od4", // App ID

  token: token




  function(response) {

            layerOptions = {

    outFields: ["*"],

    mode: FeatureLayer.MODE_ONDEMAND,

    id: 55,


    visible: true


            featureLayer = new FeatureLayer("", layerOptions);

  featureLayer.credential = credentials;



  console.log("Success: ", response.layers);


  function(error) {

   console.log("Error: ", error.message);