Problem with token used for Survey123 featureReport tool

01-13-2022 10:22 AM
New Contributor II

I am trying to use the survey123 feature report API to generate reports programmatically with Javascript.  The idea is to create an application with an interface where the user fetches the report to download.

In order to create the reports, one of the required parameters is the token generated during the login session.

To generate the token, I’m using the “@esri/arcgis-rest-auth” module.

Another way that I tried for generating the token is through the ArcGIS REST API POST request with the “generateToken” method with the following specifications:

With both token generating methods I get the same error when requesting a report. “Error: Could not generate report! An error occurred when rendering by the report engine. Failed to print map. Error: Failed to load feature layer: Invalid token.”

Is there another way for generating a valid token? Is the error related to the current token generated or is the error related to something else?

0 Kudos
4 Replies
Esri Regular Contributor

Hello @PeterDelgado,

That error seems like the report API is trying to generate the report and failing on generation maybe not so much on the initial API call. If you try running the report directly from the Survey123 web UI is the same error returned or does the report generate successfully there? 

If the report generates successfully from the Survey123 web UI try setting the referer to

Thank you,
0 Kudos
New Contributor II

Hello @ZacharySutherby,

Running the report directly from the Survey123 web UI works fine. It generates the report without any problems or errors. I can also generate the report when I put the token hardcoded in my Javascript program. But I copy this token from the browser’s developer tools when I log in to the Survey123 web UI. So doing it manually I don’t have any problems. Doing it programmatically or automated is when I get the error.

I already tried setting the referer to when generating the token through the ArcGIS REST API POST request. I get the same error with that referer.


0 Kudos
New Contributor

Hello @PeterDelgado 

Did you find a solution? I'm facing the same issue.

When I grab the token from the UI using Chrome' dev tools I'm able to produce a report using the API.

When I use a token generated by an ArcGIS API for python I can also produce a report.

But the token generated by is failing.

Thanks, Arnon

0 Kudos
New Contributor II

Hello @Arnon 

The workaround was to retrieve the token after entering the credentials for the login process. If the credentials are accepted, the access token is returned as part of the URL fragment appended to the redirect_uri (See for more details.)

I was developing in  nuxt.js, so in order to get the url string during the login…

const tokenUrl = this.$route.fullPath

And to retrieve the token…

const parsedTokenUrl = tokenUrl.split('#')

const lstTokenUrlParams = parsedTokenUrl[1].split('&')

const token = lstTokenUrlParams[0].split('access_token=')[1]

Hope this helps.

0 Kudos