How do I access user detail to fetch and post data from custom App?

In my custom App, I expect the user to fetch data and post data. What user details do I need to include in Authorization header so that they are authorize to fetch or post data?

I read in the doc for example that the payload must include username and password. In my local testing I have manually added my username and password which is not ideal. In the example app when I query the me resources I can access the username but not the password or the user token.

I also want to find out if a user can fetch data from another site into the system.

UPDATED
I remove the username and token from the header and only send the type option in the header. Now user can fetch data when they login from the data store, via the api and a third party api. However, when I tried to submit data value it is showing error 409. After inspecting the Network Tab I see the message under conflict value : "Period: `null` is not open for this data set at this time: `2YYUEZ6I1r9`"

@rithvik @didate @austin @jaime.bosque

AFAIK the API supports basic auth (not sure if deprecatd) and session tokens. You could use both to send / retrieve data.

Regarding the period, I believe you need to specify the period on your request. Not sure if you are following the official developer guide: Developer Manual - DHIS2 Documentation but there you can find the parameteres listed as mandatory.

thanks @jaime.bosque if there is session token, then we can persist the user session longer or set it to last longer than the current experience. We are having challenge now where after login due to poor network the user may be logged out or after some minutes they are logged out. Due to poor network here the user may not be able to login especially when they are in the field and that may paralyze the activity for the day. Is there a way to persist the user session to last longer than the current session and not automatically logged out users?

In the current application we are using we try to give it the offline first experience because of poor access to internet.

I have absolutely no idea… I am user someone from @dhis2-backend can help you with that :slight_smile:

@jetisco4u the default session timeout is 3600 seconds or one hour. This can be configured at the system level in dhis.conf using the system.session.timeout = 3600 parameter. If you are seeing sessions expire “after a few minutes” it is likely that your system is configured with a very short session timeout.

It is not possible (and definitely not recommended) to extend the user session cookie longer than the configured timeout at the application level, as this would circumvent the security controls chosen by the system administrator.

There is built-in support for offline operation in the application platform (see this blog post), but it is up to the application to manage offline state and data at this time. We will be adding functionality for managed offline mutation queuing in the future. If you are looking into using this functionality please reach out to myself, @Rene, or @kpvandivier so that we can help you determine the most secure and performant approach.

@austin thanks the dhis.conf should be able to do the magic. I will update it because I deploy in a custom docker container. Let me see how the experience looks like.

@austin I built a custom app using the app platform for data capturing more like trying to make one of my existing data entry app work on dhis2. In the app I am using a combination of service worker, idb used by pwa, local storage, bgSync and manual bulk upload of data values. It was a very successful experience. I want to replicate same with dhis2.

My main challenge will be if the user is logged out all the time. But I will follow your suggestion to use the dhis.conf to extent the session timeout. For now I have uploaded my app and it is working as expected except for the bgSync and bulk upload which I have not completed and tested with dhis2.

I enabled pwa for the app and noticed that when I make changes and upload again, it brings the update alert box. On web when I click it works and reload the app but on mobile when I click it will not respond until I cancel.

If I have any challenge I will tag you and the others.