How to make an api request for editing a submitted instance

Hello Kobo team and community. I hope you are doing well and having good health.

I am creating a web map on ArcGIS Online making use of the submitted data of a specific form in KoboToolbox. I used power query in Excel for connecting to the form. Then, I published the data as hosted feature layer to be used in ArcGIS Web Map. I also wrote a python script to update the layer when the data is updates on Kobo. When the user click on a point on the map, Pop up will appear that contains few information about that point along with a link to edit its data through koboToolbox. The steps would be as follows:

Step01: The user click the point on the map
Step02: Popup window appears showing the edit link for making API requests to edit the data of that point (instance) in KoboToolbox.
Step03: The user click the edit link , new tab in the browser opens and the login page of kobo toolbox open asking the user for their credentials. The user fill the credentials and redirected to the instance to be edited.

The challenge is how to to construct working edit link for specific instance in KoBo. I tried to use the following api call:
https://kobo.humanitarianresponse.info/api/v2/assets/akj5HssCp67JRVMV9PqVp6/data/119085042/edit/?return_url=false

But it didn’t work. I guessed the problem is in the authentication. I don’t have enough information on how to construct the api call with authentication.

Your support would be much appreciated.

I could be overlooking something, but I don’t think we have a great way to do this. A quick and dirty way to prompt for credentials and then redirect to another KoBo endpoint is to use https://kobo.humanitarianresponse.info/accounts/login/?next=[destination], where [destination] in your case would be /api/v2/assets/akj5HssCp67JRVMV9PqVp6/data/119085042/edit/?return_url=false:

https://kobo.humanitarianresponse.info/accounts/login/?next=/api/v2/assets/akj5HssCp67JRVMV9PqVp6/data/119085042/edit/?return_url=false

This does “work” in the sense that it prompts for a username/password and then, if you have permission, shows you the one-time-use Enketo link for editing that submission in a JSON response. In Firefox, it’s not so bad, because it has a built-in, fancy JSON renderer that turns URLs into hyperlinks. In other browsers, your users would probably have to copy and paste a URL into the address bar :slightly_frowning_face:

3 Likes

Thank you so much Dear jnm. That is very helpful and it resolves the issue. Again, Thank you so much.

3 Likes

I have the same issue, and I think I’m close to solving it but I’m not figuring out what this number (119085042) in the url is.
I’ve tried using instance id and uuid but nothing worked.

It is the instance / submission ID, which is displayed as _id in most parts of the application (UI, data API JSON responses).

1 Like

@jnm :upside_down_face: not working

@nartabaza, could you provide some more detail, please? Do you get an error code like 404, 403, etc.? Are you logged in as the owner of the project, or as someone with particular assigned permissions?

We don’t yet have enough information to help you or identify a problem with the software.

@stephanealoo, if we can’t figure out anything after the next message, we’ll likely need to take this private and find out which account and project are specifically affected. Thanks.

1 Like

Let me tell you what I’m doing in detail:

I go to https://kobo.humanitarianresponse.info/api/v2/assets/
find my project, and copy its uid
then I copy an instance id (from the _id field) and construct the link you’d suggested above:

https://kobo.humanitarianresponse.info/accounts/login/?
next=/api/v2/assets/[uid]/data/[_id]/edit/?return_url=false#/

I have data from several deployments, so I tried instance ids from all of them.

The link always takes me to the login page, after which it gives me this message:

Not Found

The requested resource was not found on this server.

1 Like

:arrow_up: Anything else?

Hi @nartabaza, it looks like the recent update has caused this issue. We’ve updated the edit URL from /api/v2/assets/[uid]/data/[_id]/edit/ to /api/v2/assets/[uid]/data/[_id]/enketo/edit/ (so that we can also have /enketo/view) but it was meant to still be compatible with the previous URL. In the meantime, please try amending your URL and see if that solves your issue — it worked on my end.

You can track the issue here.

Edit: The fix should be deployed in the next update :+1:

Edit 2: This fix has been included in the latest release, so all should be back to normal :ok_hand:

2 Likes

We’re not quite released on OCHA yet (sorry!) but we will on Monday provided there aren’t any problems with the new code on HHI.

2 Likes

It’s released now :slight_smile: Thanks for your patience.

1 Like