There is no Forms API, so you cannot do this directly with C#. Because of this, the only option, if you want to do this programmatically, is using Apps Script.
There are workarounds, though, to "wrap" the Apps Script, and call it remotely from your C# program:
Workaround #1 (Apps Script Web App):
You could publish your script as a web app and use this as a URL endpoint that you will access with your C# application. The web app would receive the HTTP requests from your application, and edit the form. For example, you could do a POST
request with data about the items you want to edit, and use the corresponding event object to retrieve that information. It could be something along these lines:
function doPost(e) {
var formId = e.parameter.id;
var itemId = e.parameter.itemId;
var form = FormApp.openById(formId);
var item = form.getItemById(itemId);
var values = e.parameters.values;
item.asListItem().setChoicesValues(values);
}
Workaround #2 (Apps Script API):
Another way, if you want to edit your form remotely from your C# application, is to use Apps Script API to create and run the Apps Script project that contains the code for editing the form. Beware, this is not an easy way, and it would take several steps:
- Get access to the Form via OAuth 2.0.
- Using this library, create a project with Apps Script API, by using the method projects.create. I'd suggest you to create a project that is bound to the Form, so that you don't need to authorize the script when it's time to execute it. If you do that, you would need to specify the
parentId
in your request body (and in your script you could use FormApp.getActiveForm()
instead, which wouldn't require authorization).
- Using the
scriptId
retrieved from the response in previous step, call projects.updateContent, in which you would have to add the code corresponding to the files in your project.
- Call scripts.run to execute your code an update your form. If you have created a standalone script in step 2, you will have to authorize your project via OAuth 2.0.
Reference: