Javascript function returns code:499, token required - how can I query the feature layer?

1245
3
04-08-2022 12:08 PM
Katie_Clark
MVP Regular Contributor

Hello,

I use several JavaScript functions in my survey to query features layers from the living atlas to auto-populate certain fields in the survey. (i.e. city and county name, etc)

I'd like to also query the NWI layer, which is in the living atlas but is marked as "exclusive content for subscribers". Using the same type of script like I did for the other data returns {"code":499,"message":"Token Required","details":[]}, which makes sense since it requires a login to view the data.

Is there a way to utilize the credentials that were used to login to Survey123 within a script so that I can query this layer?

Thanks in advance for any assistance!

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
3 Replies
IsmaelChivite
Esri Notable Contributor

Hi @Katie_Clark   If you are using a custom JS function to query a layer, you will need to pass the token from the logged-in user. You can get the token with pulldata("@property", "token") and then use that in your JS logic.  The only thing to keep in mind is that if your logged-in user is connecting to ArcGIS Enterprise, the token will not be valid against an ArcGIS Online layer from the Living Atlas of the World.

Alternatively, if you want ArcGIS Survey123 to handle the token business in your behalf, you can try the new Beta pullata("@layer", "getRecordAt") function.  You will find more info about this function in the last section of https://community.esri.com/t5/arcgis-survey123-blog/survey123-april-2022-now-available-in-beta/ba-p/...

As with custom JS functions, the pulldata("@layer") functions will not be able to use an ArcGIS Enterprise token against an ArcGIS Online secure layer.

 

 

Katie_Clark
MVP Regular Contributor

This is great, thanks so much for the response Ismael! I'll give it a try later today.

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
Katie_Clark
MVP Regular Contributor

@IsmaelChivite thank you so much for this! It's working.....for the most part.

Sometimes, the query is successful and it returns the JSON, as intended.

Katherine_Clark_2-1649885870506.png

Other times, it returns a 500 error.

Katherine_Clark_1-1649885848608.png

Also, on occasion I've had it just return '0' as well.

Katherine_Clark_0-1649886562516.png

Are these two errors simply due to the size of the service? I am querying this service specifically in my script.

If it is due to size, is there any method to get around that limitation?

 

 

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos