AnsweredAssumed Answered

Problem using API url in esri/request

Question asked by jbridwell_Dewberry on Jul 24, 2018
Latest reply on Jul 24, 2018 by jbridwell_Dewberry

I am trying to retrieve some json census data from an API in a script. I am using esri/request instead of the Ajax method. When I test the following in my console, it works fine:

require([  "esri/request"], function(esriRequest) {  var dataUrl=
  "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/layers"; 
    var layersRequest = esriRequest({   
        url
: dataUrl,   
        content
: { f: "json" },   
        handleAs
: "json",   
        callbackParamName
: "callback"  }); 
    layersRequest
.then(   
        function(response) {     
            console
.log("Success: ", response.layers); 
        }, function(error) {     
            console
.log("Error: ", error.message); 
        });
    });

As soon as I plug in my API for dataUrl(https://api.census.gov/data/2016/acs/acs5?get=NAME,B01001_001E&for=tract:010805&in=state:01&in=county:073), which is in json format already, I get a 400 (Bad Request) error thrown. What's the problem here?

Outcomes