Send Blank Form programmatically with C#

Hi.
I use the ODK Aggregate.
I need send to Blank Form with ODK FormUploader with Command Prompt.

For example:

java -jar "ODK FormUploader v1.4.9 Production.jar" "PATH/FILE" "ServerUrl" "user" "pass"

Its possible...???

Hmm. I didn't know many people still used ODK FormUploader!

I just checked the install instructions at https://opendatakit.org/use/form-uploader and the release notes at https://github.com/opendatakit/opendatakit/wiki/FormUploader-Release-Notes and I don't think there has never been a command line mode, but I guess we could add one. For that reason, I've moved this thread to the Features category.

Before we can add a feature, I do have a few questions though!

  1. Why are using FormUploader as opposed to just the form using a web browser to ODK Aggregate?
  2. It sounds like you need a command line mode for uploading forms. Can you tell me more about why you need this feature? Is it for scripting some interaction? Is it because there is no clean API for integration?
  3. Would you be opposed to us putting the FormUploader functionality (but the user interface and proposed command line interface) into ODK Briefcase app? They share the same code base, and it'd be nice to just have to manage one app.

Hi, thanks for reply.

I am using odk as a survey system and I have a data visualization system in C#.

With c # I generate an excel that I convert to xml with the xlsform tool through a command, now I want to take that xml and automatically send it to ODKAggregate.
To be transparent to the user.

Thanks for help.

Rather than use the ODK FormUploader, you can use the Aggregate API for uploading a form. That API is documented at https://bitbucket.org/javarosa/javarosa/wiki/FormSubmissionAPI.

You can find an implementation in Java at https://github.com/opendatakit/briefcase/blob/master/src/org/opendatakit/briefcase/util/AggregateUtils.java#L646 and one in Ruby at https://github.com/opendatakit/build/blob/master/server/odkbuild_server.rb#L239.

You can also upload forms with curl
curl --verbose --digest --user MyManagerUser:MyManagerPassword --header "Content-Type: multipart/form-data" --form "form_def_file=@/tmp/MyForm.xml" https://example.com:8080/ODKAggregate/formUpload

1 Like

Thanks for reply.

I will do what he proposes and comment if everything goes well.

1 Like

Hi.

With advice before I create this in C#.

Use the tool: http://restsharp.org/

And use the following code:

        var client = new RestClient("http://host:port/ODKAggregate/formUpload");
        
        var request = new RestRequest(Method.POST);
        request.Credentials = new NetworkCredential("user", "pass");
        request.AlwaysMultipartFormData = true;
        
        request.AddFile("form_def_file", @"E:\sample_xlsform.xml");
        
        IRestResponse response = client.Execute(request);
        
        var content = response.Content;

The response is:

I hope this code is of help to others

Thanks.

3 Likes

Nice, @Me890506, thanks for sharing your code! If your visualization system is something you can share more about, consider posting in Showcase! I know a lot of groups are interested in good ways to make sense of their data after collecting it.

Hi @yanokwa

I tried to use the curl to upload a form, but it doesn't work. I wonder if the url has been changed?
My app url is https://extrasyst.appspot.com/ what should I use as the right upload url in the curl command?

What if I need to upload my .csv file? what command should I use?

Thanks