Select to view content in your preferred language

Automatically Update Coded Values

1784
10
05-17-2017 01:32 PM
TonyDaSilva1
Regular Contributor

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 

0 Kudos
10 Replies
JamesTedrick
Esri Esteemed Contributor

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.

TonyDaSilva1
Regular Contributor

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": []
}]}

0 Kudos
JamesTedrick
Esri Esteemed Contributor

The token should be a parameter in the UpdateURL component, not posted in the form data (token authorization happens before processing of form data)

0 Kudos
TonyDaSilva1
Regular Contributor

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.

0 Kudos
TonyDaSilva1
Regular Contributor

I think I have found my answer:

Limitations of App Login | ArcGIS for Developers 

Am I correct in thinking that a web service cannot automatically updated coded values of a Survey123 form?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Oh- I missed completely that you were using an application ID/secret token instead of a username based token.  Yes, that is the issue. 

0 Kudos
TonyDaSilva1
Regular Contributor

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?

0 Kudos
JamesTedrick
Esri Esteemed Contributor

The easiest way to do that would be to generate a long-life user token and use that instead of the app login.

0 Kudos
TonyDaSilva1
Regular Contributor

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 ?

0 Kudos