Hi, I was wondering if I am able to write a script to update the Survey123 Form Coded Values periodically because they are time sensitive to changes?
However I noticed that my developer application token is forbidden at the following address
https://www.arcgis.com/sharing/rest/content/users/islgispub/{accountId}/items/{ServiceId}/update
Hi,
You should be able to write a script to rezip the survey file and update. One thing to note while testing - the update resource is POST only, if you're experimenting you should use a program like POSTMAN first to get everything correct manually.
Thanks for the quick reply.
I have already written a script to update and re-zip it and send it to the /update endpoint using POST but even with a token it is giving me a 403 forbidden error.
Am I missing something?
var zipfile = File.ReadAllBytes(ZipPath);
var thumbfile = File.ReadAllBytes(ExtractPath + "\\esriinfo\\Survey.png");
var postData = new MultipartFormDataContent();
postData.Add(new StringContent("pjson"), "f");
postData.Add(new StringContent(""), "snippet");
postData.Add(new StringContent("Survey"), "title");
postData.Add(new StringContent(Token), "token");
postData.Add(new StringContent("Form, Survey123, Survey123 Connect, xForm"), "typeKeywords");
postData.Add(new ByteArrayContent(zipfile, 0, zipfile.Count()), "thumbnail", ServiceId + ".zip");
postData.Add(new ByteArrayContent(thumbfile, 0, thumbfile.Count()), "thumbnail", "Survey.png");
var response = client.PostAsync(UpdateUrl, postData);
{[error, {
"code": 403,
"messageCode": "GWM_0003",
"message": "You do not have permissions to access this resource or perform this operation.",
"details": []
}]}
The token should be a parameter in the UpdateURL component, not posted in the form data (token authorization happens before processing of form data)
I am replicating what Survey123 form data is using and Survey123 is providing the token in the form data.
Also, if I grab a Survey123's token that it generates and use it, it returns successful.
I think I have found my answer:
Limitations of App Login | ArcGIS for Developers
- Applications cannot create, update, share, modify, or delete items (layers, files, services, maps) in ArcGIS Online or Portal for ArcGIS.
Am I correct in thinking that a web service cannot automatically updated coded values of a Survey123 form?
Oh- I missed completely that you were using an application ID/secret token instead of a username based token. Yes, that is the issue.
Is there a way around this, we would like to synchronize our data with our forms without manually updating them every time the data changes?
The easiest way to do that would be to generate a long-life user token and use that instead of the app login.
Okay thanks, that's what i figured i would have to head towards... I've been reading up on OAuth2, is it possible to have the token refresh itself as 2 week expiration is not ideal ?