Pulling Latest Submission Date via API

Hello,

I’m pulling the Forms/Surveys via this API request https://eu.kobotoolbox.org/api/v2/assets.json.
This brings date_created, date_modified, and date_deployed, but I’m looking for the Latest Submission Date, which I couldn’t find it out.
Your guidance is very appreciated.
Thank you in advance for your support.
Ibrahim

1 Like

Welcome to the community, @ibrahim.hd! Have you gone through these support articles?

Hello @Kal_Lam,
Thank you for your response and apologies for my late answer as I was sick.
Coming back to my question, actually I’m asking about a very specific mattar which is the “Lastest Submission Date” when retriving all assets/forms through the link mentioned in my first message without the need to iterate over every single Form separately. (I mean getting that date in some way the same as the other dates are pulled out.)

Please let me know if any further clarification is needed.
Thanks in advance,
Ibrahim

The response from /api/v2/assets.json doesn’t include the “Lastest Submission Date” but you can get it from the /v2/assets/${formId}/data endpoint which access the submissions.

You will likely need to draft a script to do this. In a nutshell:

  1. Get all forms using /api/v2/assets.json
  2. Get submissions for each form using /v2/assets/${formId}/data. Unfortunately you cannot rely on the property deployment__submission_count, so I suggest breakdown it down in 2 calls:
    • 1st call with query string limit = 1 to get submissions count
    • 2nd call again with query string limit = 1 & start = {count - 1} to get the last submission.
      So it will work even if your forms have more than 30k submissions and will prevents fetching all the submissions (quicker in most cases).
  3. Access _submission_time property.

Find below a Javascript implementation using https://github.com/DRC-UA/kobo-sdk:

import {KoboClient} from 'kobo-sdk'

const sdk = new KoboClient({
  urlv1: 'https://kc.kobotoolbox.org',
  urlv2: 'https://kf.kobotoolbox.org',
  token: '<YOUR PRIVATE TOKEN>',
})

const forms = await sdk.v2.form.getAll()
for (const form of forms.results) {
  const formId = form.uid
  const count = await sdk.v2.submission.get({formId, filters: {limit: 1}}).then(_ => _.count)
  const last = await sdk.v2.submission.get({formId, filters: {limit: 1, offset: count - 1}}).then(_ => _.results[0])
  console.log(last._xform_id_string + ': ' + last._submission_time)
}

Result:

aDpk4iBc9XKrUfUoeXFSQe: Tue Feb 04 2025 20:14:57 GMT-0500 (Colombia Standard Time)
ajhmJ9rXMQ9ehpUoCEzqdP: Wed Feb 19 2025 11:57:27 GMT-0500 (Colombia Standard Time)
1 Like

Thank you @alexandreannic for your informative answer.
I would appreciate it if you could help share some resources that guide implementing the same approach in MS Power BI in a relatively easy and efficient way.
Thank you so much in advance.
Ibrahim

You could try to pre-process using Power Automate but I’m not familiar enough with the solution to support.

Hi, can you elaborate little bit? what are you trying to achieve so i can try to help

1 Like

Hi @osmanburcu

Actually, as a part of a monitoring and activity tracking Power BI dashboard, the “Lastest Submission Date” needs to be presented.
The following API endpoint has been utilized to pull the assets/forms:
https://eu.kobotoolbox.org/api/v2/assets.json
However, it doesn’t retrieve the “Latest Submission Date” for the Forms pulled.
My inquiry is as follows: is there any different API endpoint that retrieves a list of all Forms with their respective “Latest Submission Date”? If not, how this can be implemented in a relatively simple and efficient way in MS Power BI?

Thank you.

I am not sure if it is possible, i don’t remember any API point to retrieves the list of forms with the latest submission date. If you don’t have a lot of forms, i would suggest to use https://youtu.be/53Se9rWc9bc this method and only collect the submission date from the from.

1 Like