Survey123 item property to determine whether the survey is accepting responses

203
5
2 weeks ago
Labels (1)
MillerDerek
New Contributor II

Working with Survey123 items in ArcGIS.com, is there a property exposed anywhere in the system that identifies whether an item is accepting responses?

I've checked the following documentation and have not been able to find any such property:

Survey item properties returned via SurveyManager in ArcGIS API for Python - https://developers.arcgis.com/python/api-reference/arcgis.apps.survey123.html#arcgis.apps.survey123....

Item reference in the rest api - https://developers.arcgis.com/rest/users-groups-and-items/item.htm

 

Tags (3)
0 Kudos
5 Replies
MillerDerek
New Contributor II

@ZacharySutherby do you have any insight on this?

0 Kudos
ZacharySutherby
Esri Regular Contributor

Hey @MillerDerek,

There's a few aspects to this and depends on where you're looking to use the information.

 You can control "accepting responses" on both the Survey123 form item side and/or the feature service side too. So depending on where you're looking to control this depends on where you'll need to look. 

From the Survey123 form item side you have the ability to set a survey status in the Survey123 website to open or closed. Closed being not accepting responses and open being accepting responses. With this though it doesn't control anything on the feature service so the survey can be "closed" but the feature service could still be pulled into a web map and edited. This open/closed status on the Survey123 form item is stored in it's .info file which isn't exposed through the item properties like you see in the ArcGIS API for Python. 

You can access the .info file through the sharing/rest URL by accessing: 

https://<webContextURL>/sharing/rest/content/items/<surveyItemID/info/<surveyName>.info?f=json&token... 

The open/closed status will be under webformInfo  -> settings -> openStatusInfo -> status 

 

On the feature service side you can also check if add/update/delete capabilities are set on the service. 

 

Not sure what your full use case is but if you're looking to use an open/closed status in the Survey123 field app, the field app doesn't support the setting from the website, but what you can do is use a custom JavaScript function (assuming the survey isn't to be shared publicly) to query the sharing/rest endpoint, obtain the status, then set up a constraint based on the status to prevent submission.  

Thank you,
Zach
0 Kudos
MillerDerek
New Contributor II

Thanks, Zachary.

Current use case is a simple read-only property to use in some internal admin tools.

I'm getting the following error:

{'error': {'code': 400, 'messageCode': 'CONT_0001', 'message': 'Item does not exist or is inaccessible.', 'details': []}}

Request URL I'm using is:

https://<<org arcgis online root>>/sharing/rest/content/items/<<item id>>/info/<<item name>>.info?f=json&token=<<token returned via /generateToken>>

Am I missing something? URL formatted properly?

Thanks 

0 Kudos
ZacharySutherby
Esri Regular Contributor

Hello @MillerDerek

The URL looks to be formatted correctly, one thing to check is the <<item name>> is encoded for example "Test survey" vs "Test%20survey". 

If it's a web designer survey you may need to use https://www.arcgis.com/sharing/rest/content/items/<itemID>/info/form.json?f=json&token=

Are you obtaining your /generateToken from an automated API call or from the Survey123 website? One thing you can test is setting the referer to https://survey123.arcgis.com/surveys.

You can also see the request if you access the Collaborate tab in the Survey123 website you can filter the network traffic based on .info and it should return the request that Survey123 makes. 

This note shouldn't play a role in the error observed, but I'll note not all surveys will have a webformInfo section in the .info file. If the survey was published from Connect it may or may not have it. 

Thank you,
Zach
0 Kudos
MillerDerek
New Contributor II

Hi @ZacharySutherby 

Thanks for the tip on seeing the request from within S123.

Survey123 is sending a request to /sharing/rest/content/items/{itemID}/info/form.json

I'm able to access that via a REST call, and it contains the same form.json file as the zip directory returned by /sharing/rest/content/items/{itemID}/data

The latter was my fallback workaround that I hoped to avoid, and this should do it.

To answer your token question - token is generated via an API call to /generateToken. The request to {itemID}/info/form.json succeeds with a token generated with a referer set to https://survey123.arcgis.com or <<my arcgis.com org>>, as well as client token with client = 'requestip'.

 

Thanks @ZacharySutherby 

via {'client':'requestip'}, {'referer':'https://survey123...'}, and {'referer':<<my arcgis.com org>>}

0 Kudos