Get Pre-filled Enketo Submission Link from API

We need to create a link to a new submission, where that submission is pre-filled using answers from a previous survey.

I found the online Enketo API documentation for Creating a new Survey

API Params:

* required parameter **`server_url`** is the url of the OpenRosa server your form is hosted on
* required parameter **`form_id`** is the ID of the form listed in https://testserver.com/bob/formList
* optional parameter **`theme`** can be used to centrally override the theme for all subsequent users, or to reset the theme with an empty string value
* optional parameter **`defaults[]`** can be used to dynamically override survey field defaults (`defaults[/path/to/node]=value`)
* headers must include a **valid API key as username in the Authorization header**

The current issue we are having is that this request is always returning a 401 Unauthorized error.

cURL we are using to attempt to get the survey link

curl --user <API_Token>: -g -d "server_url=https://kc.kobotoolbox.org&form_id=<FORM_ID>" https://ee.kobotoolbox.org/api/v1/survey

The API_Token variable is retrieved from the online Kobo dashboard account security page.
(KoboToolbox)

and the FORM_ID is retrieved from the Kobo API endpoint https://kc.kobotoolbox.org/api/v1/forms

We are currently using https://ee.kobotoolbox.org as the enke.to api domain because that is the domain that a new survey uses when we open a survey from the Kobo dashboard page My Projects -> From Name page -> FORM -> Collect data -> Online-Offline => OPEN

The idea is that we then generate the defaults query parameter based on the users last submission, but we cant even get the Enketo API to generate a blank survey link.

I’m not very experienced with using Kobo or Enketo, and currently it is pretty unclear where I am going wrong because there are too many variable which could potentially be incorrect about our setup.

@trevorjpuckett, these posts discussed previously should give you some clue …

And this one too …

@Kal_Lam Thanks for the resources! I skimmed through those and didn’t see any mention of authentication issues. I think currently our major blocker is that the cURL request mentioned above always returns a 401 Unauthorized, and I am using the authentication schema the Enketo API outlines in combination with the API Token for my user account that i retrieved from the Kobo dashboard.

For those who stumble on this with the same issue it came down to a simple misconception. I believed that we had to utilize the Enketo API endpoint POST /survey to create a survey everytime a user wanted to create a blank submission. This turned out not to be true, and we were actually able to use the url from the kobo dashboard, and simply provided the d[path/to/field]=valueToUse query parameters to that url.

1 Like