Printing secured services...

08-02-2019 09:42 AM
New Contributor II


ArcGIS Server Version: 10.7 (ArcGIS Online) 

ArcGIS JS API: 3.29


In my web application, I am consuming secured services properly loading the map and have a requirement to print the map contents.

Initially, the token expiry was set to default (i.e. 60 mins) and everything worked fine including printing, using the Utilities/PrintingTools GP Service.


As part of the requirement, the token expiry was increased from 60 mins to 240 mins - everything still worked fine except for printing! Looking up the Esri help it was clear I had to create a custom service. I created the custom service as described in the help documents, but it still fails with the following error:

Error executing tool. Export Web Map Task Job ID: jb88972125ace4b6593c8055ee779e920 : Layer "xxxx": Unable to connect to map server at https://xxxxx/arcgis/rest/services/xxxx/MapServer/. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task).

Any suggestion this issue occurs with particular layers on ArcGIS Online? If those layers are turned off then print tool works properly.



Sai Anand

0 Kudos
5 Replies
Esri Regular Contributor

Hi Sai. So just to be clear, the layer in question is hosted in ArcGIS Online? And the custom print service is hosted in ArcGIS Server? And where did you increase the token expiration date? In ArcGIS Server or ArcGIS Online?

Also, can you verify that the token is being passed to the print service? If so, is there any other information as part of the error message about the token? Does clearing the cache change any behavior?

New Contributor II

Hi Noah Sager,

Yes, Layers are hosted in ArcGIS Online. Yes, custom print service is hosted in ArcGIS Server. Increase the token expiration time on ArcGIS Online. My custom print service is not secured. And Shred the Print Service rest endpoint on the ArcGIS Online Content. But, still causing an issue. This behavior is only for a few layers. I tried permutation and combination with layers and check the difference between one was working perfectly fine with my custom print service but some layers are throwing this error.

Error executing tool. Export Web Map Task Job ID: jb88972125ace4b6593c8055ee779e920 : Layer "xxxx": Unable to connect to map server at https://xxxxx/arcgis/rest/services/xxxx/MapServer/. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task).

Can you let me know how to check the token is being passed correctly or not the web map JSON to print Service? Those ArcGIS online layers are working fine, I can perform query and popup task. But only get failed when trying with Print Service.


Sai Anand Peketi

0 Kudos
New Contributor III

Hi SaiAnand Peketi‌,

I've used this workaround since 10.3 and still using it with 10.7 (hopefully the same issue):

Set the token expiry time and the custom print service recycle time to the same value. So if you need short token expiry to be 240, change the print service recycle to 240 as well.

Hopefully this is the issue and it can help.

New Contributor II

Thanks for reply @Bryan McIntosh. I tried to change the recycle interval but not a success. 

0 Kudos
New Contributor II

I used sample Print Widget template and set the proxy to login the ArcGIS online Feature service. That's one is loading properly on the map but failed Print Service. 

var permitUrl = "";

If I add the token manual then print service is working. Not sure why manual need to set the token for a print widget. Again this only for few layers, not all feature services.

var permitUrl = "";

Snippet code of Print Widget. Let me know, did I make any mistake.

var app = {};
"esri/map", "esri/layers/FeatureLayer",
"esri/dijit/Print", "esri/tasks/PrintTemplate", "esri/tasks/PrintTask",
"esri/request", "esri/config",
"dojo/_base/array", "dojo/dom", "dojo/parser", "esri/urlUtils",

"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function (
Map, FeatureLayer,
Print, PrintTemplate, PrintTask,
esriRequest, esriConfig,
arrayUtils, dom, parser, urlUtils
) {

app.printUrl = "https://xxxx/arcgis/rest/services/xxx/GPServer/Export%20Web%20Map";
urlPrefix: "", //Server URL
proxyUrl: "proxy.ashx" // Path of Proxy page mine is avaiable on the root folder
}); = "proxy.ashx"; = new esri.Map("map", {
basemap: "hybrid",
center: [-85.797466, 38.120622],
zoom: 17,
slider: false

// add graphics for pools with permits
var permitUrl = "";

//var permitUrl = "";
var poolFeatureLayer = new FeatureLayer(permitUrl);;

// get print templates from the export web map task
var printInfo = esriRequest({
"url": app.printUrl,
"content": { "f": "json" }
printInfo.then(handlePrintInfo, handleError);

function handlePrintInfo(resp) {
var layoutTemplate, templateNames, mapOnlyIndex, templates;

layoutTemplate = arrayUtils.filter(resp.parameters, function (param, idx) {
return === "Layout_Template";

if (layoutTemplate.length === 0) {
console.log("print service parameters name for templates must be \"Layout_Template\"");
templateNames = layoutTemplate[0].choiceList;

// remove the MAP_ONLY template then add it to the end of the list of templates
mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");
if (mapOnlyIndex > -1) {
var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];

// create a print template for each choice
templates =, function (ch) {
var plate = new PrintTemplate();
plate.layout = plate.label = ch;
plate.format = "PDF";
plate.layoutOptions = {
"authorText": "Made by: Esri's JS API Team",
"copyrightText": "<copyright info here>",
"legendLayers": [],
"titleText": "Pool Permits",
"scalebarUnit": "Miles"
return plate;

// create the print dijit
app.printer = new Print({
"templates": templates,
url: app.printUrl
}, dom.byId("print_button"));

function handleError(err) {
console.log("Something broke: ", err);



Sai Anand Peketi

0 Kudos