Using Central API to access Collect QR code

Hi again,

Thanks so much for helping on my previous query! Apologies if this is a daft question, I see in the central API, we can list users, download data etc... I was wondering whether their was any way to access app users QR codes through the API???

Thanks :slight_smile:

Hi @lgorman!

The QR code that's shown in ODK Central encodes a server URL to be used in ODK Collect. For a particular app user, that URL is:

…/v1/key/[token]/projects/[projectId]

You can obtain the token and project id using the API endpoint to list a project's app users. To learn more about the /key/[token] prefix, see here.

In other words, you can use data from the API to construct the server URL to be used in Collect. However, the API does not return an image of the QR code. Is there a reason you need API access to the image in addition to the server URL? If so, it'd be great to get as much detail as possible about your process / use case.

3 Likes

Hi @Matthew_White!

Ah perfect, I think I understand. Apologies, a lot of this is quite new!

I thought it might be useful give a little explanation of what I am trying to do anyways though :slight_smile:

I am developing a localisation form (on excel or something probably). I would like for people who are interested in using our survey to fill this document out. I am working on a python script that uses this form to produce a localised version of our survey (as an xlsx). I would like the scripts to create a new project, upload the form, create a new app user and then return the information that the user needs to configure ODK collect (which is why I was hoping for the QR code but you have answered my question :slight_smile:) .

Thanks very much for your help. Would love to hear anyone's thoughts on this, and once again apologies if my questions are a little basic!

Cheers!!!

Interesting! Is it possible to use XLSForm multiple language support for this localization so that you have a single form?

Also, rather than creating a separate project for each form, could you just create a new app user in the same project? Different app users can have access to different forms, which you can configure using the API.

Hi @Matthew_White,

Apologies, I wasn't fully clear. I will try to answer both of your queries.

Is it possible to use XLSForm multiple language support 2 for this localization so that you have a single form?

We are making use of this great feature already! When I mean localisation, I mean providing locally sensible choices.

To give a bit of context, our survey is about farmers. The list of potentially important crops in a particular country is quite large. So during localisation we allow users to select which crops/livestock they want to include in the survey. Also, any locally sensible units are added to the survey.

I also want users to be able to select "modules" or sections that we have developed previously when designing the survey.

Both of these tasks, when we are adapting our surveys for people, require a lot of manual/repetitive changes in excel. I am hoping that my little python scripts will be able to take out some of the repetition.

Also, rather than creating a separate project for each form, could you just create a new app user in the same project? Different app users can have access to different forms, which you can configure using the API.

Ah I did not know this was possible. My one worry is that I would not want app users to have access to one another's submitted forms. Would this be possible with what you describe? What is the advantage of having them all within the same project?

Essentially, I want it to be as simple as possible for people to open ODK collect and go to the field with out survey. When I construct the server URL, do I also need the new users to specify a password?

---------------------------

Edit:

I think the answer I may be looking for can be found here:

All I need is to generate a QR code with the correct server URL. Am I right in guessing that I can do it using this dictionary structure?

Thanks so much again, it's been really great to see how engaged and helpful this community is. Hopefully one day I will have something useful to contribute!

Interesting, that additional context is useful!

Yes, this is definitely possible by managing form access. The documentation for that is here, and you can also manage form access using the API.

Perhaps not much, so if your current workflow is working, there might not be strong reason to change it. However, having a single project might make it easier to access the submission data using the API: getting the list of forms would be a single API request, rather than a request to list the projects, then a request for each project to list the project's forms.

Users won't need to specify a username or password in ODK Collect: the server URL for the app user is sufficient to authenticate.

You actually don't need to specify all those keys, as most keys have sensible defaults. (Also, I'm not sure that's the most up-to-date list of keys. You might be interested in the discussion here.) You only need to specify the server_url key. (You should specify both general and admin, but admin can be empty.) For example:

{
  "general": {
    "server_url": "…/v1/key/[token]/projects/[projectId]"
  },
  "admin": {}
} 

The topic you linked to seems like a good place to start given that you're working in Python! It's in JavaScript, but you can also check out how we create the QR code in ODK Central here.

1 Like

For an up-to-date list of keys, see https://docs.getodk.org/collect-import-export/#list-of-keys-for-all-settings.

3 Likes

I also just remembered that there was a similar request on GitHub for API access to the QR code: https://github.com/getodk/central/issues/123. I've also linked to this discussion from GitHub.

2 Likes

Hi @Matthew_White @LN,

Thanks so much for all your help again! This should be more than enough to get my teeth into!

I will post to the forum if any useful products come out of this :slight_smile:

All the best,

Leo

2 Likes