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

I made changes to my question types last month so I have to edit the old submissions to fit the new format (from a string question to integer question with another string question for remarks) .
I have problems with the table ui not loading sometimes/slow . Is there a documentation on how to do this via API?

I found this link: How to make an api request for editing a submitted instance
But I have no idea how to do this step by step especially the JSON generation part.

The R httr call for this is similar to the download request?
My idea is to download the whole csv and make the necessary corrections and loop for each changed row.

Even a list of general steps is helpful.

PS: This is also better because I will have the copy of edited and unedited files in my computer. Easier to track changes rather than editing in the UI.

I’m trying again with a recent project but still not working.
I’m using this url:
https://kobo.humanitarianresponse.info/api/v2/assets/azq8z4LQhekcmWta8RTyra/data/313064979/enketo/edit/?return_url=false
and getting this in Chrome:
{"url":"https://ee.humanitarianresponse.info/edit/EKcAVZkP?instance_id=f83e5a8c-e4e6-44bb-99c7-9524ffd77d45&return_url=false"}

refreshing the page after that, gives a different message:
{"detail":"Enketo error: Not allowed. Record is already being edited"}

any suggestions?


Update:
Copying the url that I got from the browser worked!
I’d still appreciate it if there was a way to directly redirect to it.

Hi @nartabaza, if you refresh the page, i.e. make another request for editing, in less than 30 seconds after the previous request, it will show that error. It is a crude way to prevent multiple simultaneous edits to a submission. Regarding redirects, the Kobo UI makes this same API request and then handles the redirect — so you will have to do similarly if that’s the behavior you’re wanting.

1 Like

but how do I handle the redirect if the link is constructed in powerBI and the user is coming from a published report? is there something I can add to the url?

Hi Everyone,

Is it possible to edit kobo submission data by using URL link ?
I try to goggle it, I found that it is possible following this pattern :

/api/v2/assets/{uid}/data/{id}/view/?return_url=false

I hope someone can give an example of this, so i can follow. I am already stuck to create this.
really need help

@Josh Is it possible to give us an example of this ? didn’t really understand how to create it. :smiling_face_with_tear:

Hi @Josh , would you like to help about this. I am quite stuck

Hi @nartabaza currently the frontend handles the redirection, but I have created an issue here to account for your use case and similar requests previously:

3 Likes