I'm trying to use the Export function off of an ArcGIS Online feature service, but I keep getting an error:
Export Excel Error: [request:server]: Unexpected token < in JSON at position 0
When I try to send the URL directly, I get this error:
The requested layer (layerId: export) was not found.
This is the code I'm trying to use:
// Export to excel
btnExport = document.getElementById("btnExport");
btnExport.onclick = function () {
let exportURL = "https://services2.arcgis.com/2t1927381mhTgWNC/arcgis/rest/services/Regional_Bus_Stops/FeatureServer/export";
exportURL += "?itemId=9feab4597b8d435e9c9ba41a4931d09f";
exportURL += "&title='Regional_Bus_Stops'";
exportURL += "&exportFormat='Excel'";
exportURL += "&exportParameters=" + "%7b'layers'%3a%5b%7b'id'%3a0%7d%5d%7d";
console.log(exportURL);
esriRequest(exportURL, {
method: "post",
responseType: "json"
}).then(function (response) {
console.log(response);
})
.catch(function (error) {
console.error("Export Excel Error: " + error);
});
}
I think it has something to do with how I'm passing the Export parameters. I've cleaned up the 'layer:0' text using URL encoded values, but that still doesn't seem to work. Any help would be greatly appreciated.
Thanks, Jeff.