Problem using the new Kobo API - cannot POST to create a new form

Hi all,

I’m trying to use the new Kobotools API to create a new form. I’ve tried 2 things, and both times my POST request has been redirected with a 301 response (and have turned into GET requests…). Here is what I tried:

  1. POST to https://kf.kobotoolbox.org/imports, using the process described in @jnm 's excellent post.

  2. POST to https://kf.kobotoolbox.org/api/v2/assets/, using a payload matching the one described in the draft documentation.

Both times, my requests return the response I would expect from a GET request to those urls. I’m testing in both Postman and with Guzzle / Php. Below is the output from the “debug” mode of Guzzle, which suggests my requests are being 301 - redirected into GETs.

In option 1 (https://kf.kobotoolbox.org/imports), I had requests working fine a few months ago. These same requests today have given me this issue, so I assume something has changed on the API side…

Is this a bug in a recent build of the API? Am I doing something wrong? I know the Kobo API is still in development, but the old V1 API only works properly with the legacy interface, so I’m keen not to have to go backwards in order to get our form uploading to work…

Any insights are appreciated - also please let me know if this is just a temporary issue and I should just wait for a few days to carry on development!

~ D.

Hi,

Any news on this issue? I’d like to know if what I’m doing is supposed to work, or if the API has changed since September and I should be using some new endpoint to publish new XLS forms?

We had our demo system working in September, which did the following:
POST to https://kf.kobotoolbox.org/imports, with a payload of

library=false,
file=@path/to/xlsform.xlsx

Can anyone from the Kobotools dev team tell me the correct method of doing this task with the new API? I’m a little concerned that the new API isn’t yet ready while the old API is no longer recommended.

Thanks in advance,
~ D.

Hi @degami

Sorry you had to wait awhile for a response to this. Have you tried https://kf.kobotoolbox.org/imports/ instead of https://kf.kobotoolbox.org/imports?

The trailing slash is very important when POST ing data to API, because Django redirects urls without trailing slash to their counterparts with a trailing slash and when the redirection occurs the POST data is lost.

2 Likes

Hi @mike.destaubin,
Thanks for the reply - a very good message to return to in the new year :-). I can confirm that by adding the trailing slash to /imports/, my code from a previous incarnation is working as expected again. Useful to konw re: Django’s handling of the urls.

I also got the 2nd option working (POST to https://kf.kobotoolbox.org/api/v2/assets/) - and by adding a “content” json paramater I could create a working form ready to be published - very nice!

Thanks again for your help - I’m very glad it was a simple syntax error on my part!

~ D.

2 Likes