How to make an api request for editing a submitted instance

@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

Hi @taufik_maggangka, can you please clarify what you are trying to achieve and where you are stuck :slightly_smiling_face:

1 Like

This is the full url pattern:

(https://kobo.humanitarianresponse.info/api/v2/assets/[uid]/data/[_id]/enketo/edit/?return_url=false)

there are two variables that you need to insert in this url for it to work: the [uid] and the [id].

The [uid] is a string that refers to a specific project. to get the [uid], open your project and check the url that is in the address bar. It should be something like this:
https://kobo.humanitarianresponse.info/#/forms/azq8z4LQhekcmWta8RTyra/summary

The text between ‘forms’ and ‘summary’ is your [uid]

the [id] comes with each submission under the column name [_id]

I create a simple excel function to formulate this url for every submission. It should look something like this: https://kobo.humanitarianresponse.info/api/v2/assets/azq8z4LQhekcmWta8RTyra/data/316312587/enketo/edit/?return_url=false

When clicking the resulting url, it will return another url in the browser (this new one is temporary and works only one time). Copy the emerging url into the address bar and you’ll get to to your submission to edit it.

I hope this helps.

2 Likes

Hi @Josh ,
Basically, I would like to edit kobo submission by API.

I saw your issue that raised, to follow this patten:
/api/v2/assets/{uid}/data/{id}/view/?return_url=false

But dont really understand, it is why I asked for an example.

Hi @taufik_maggangka, if you are wanting to make edits directly through the API (not within Enketo) you can refer to the thread here for more details:

1 Like

Hello,

Does this still work? I have tried this with my project as per the instruction and get the following message: “{“detail”:“Not found.”}”

The same happens when clicking the link in this post.

Cheers