User PUT issue

Can someone tell me what I am doing wrong here? According to the docs (https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update) this should work to update a user’s account:

curl -X PUT -u “admin:district” -d @u.json -H “Content-Type: application/json” https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge

In this case I am using {“firstName”:“ATEST”} as the u.json file. Unfortunately I keep receiving errors such as:

“Missing required property surname.”

If I send a more complete user object it complains that I am missing the userCredentials.username property. When I add that, it complains that user already exists.

Gregory Wilson

Greg,

When you send the more complete user object, do you include the userCredential object’s id?

Vlad

···

On Tue, Aug 14, 2018 at 5:16 AM Greg Wilson gwilson@baosystems.com wrote:

Can someone tell me what I am doing wrong here? According to the docs (https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update) this should work to update a user’s account:

curl -X PUT -u “admin:district” -d @u.json -H “Content-Type: application/json” https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge

In this case I am using {“firstName”:“ATEST”} as the u.json file. Unfortunately I keep receiving errors such as:

“Missing required property surname.”

If I send a more complete user object it complains that I am missing the userCredentials.username property. When I add that, it complains that user already exists.

Gregory Wilson


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Hi Greg,

To avoid such errors, you only need to update the username from the original file you used while POSTing, it should work.

Regards

···

Sent from Mail for Windows 10

From: Greg Wilson
Sent: 14 August 2018 11:16
To: DHIS 2 developers
Subject: [Dhis2-devs] User PUT issue

Can someone tell me what I am doing wrong here? According to the docs (https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update) this should work to update a user’s account:

curl -X PUT -u “admin:district” -d @u.json -H “Content-Type: application/json” https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge

In this case I am using {“firstName”:“ATEST”} as the u.json file. Unfortunately I keep receiving errors such as:

“Missing required property surname.”

If I send a more complete user object it complains that I am missing the userCredentials.username property. When I add that, it complains that user already exists.

Gregory Wilson

Looks like I might have been providing too much of the model info (lastsaveddate and such). Would be great if the docs listed the bare minimum properties.

Gregory Wilson

···

On Tue, Aug 14, 2018 at 5:37 AM Dusabe Eric duserik@gmail.com wrote:

Hi Greg,

To avoid such errors, you only need to update the username from the original file you used while POSTing, it should work.

Regards

Sent from Mail for Windows 10

From: Greg Wilson
Sent: 14 August 2018 11:16
To: DHIS 2 developers
Subject: [Dhis2-devs] User PUT issue

Can someone tell me what I am doing wrong here? According to the docs (https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update) this should work to update a user’s account:

curl -X PUT -u “admin:district” -d @u.json -H “Content-Type: application/json” https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge

In this case I am using {“firstName”:“ATEST”} as the u.json file. Unfortunately I keep receiving errors such as:

“Missing required property surname.”

If I send a more complete user object it complains that I am missing the userCredentials.username property. When I add that, it complains that user already exists.

Gregory Wilson

Hi Gregory,

For updating a single field on a user record, I would try doing a PATCH request with exactly the same payload as you were doing.

I do this type of request to disable a user in the User Management app, so it should work.

Best regards,
Hendrik

···

On 14 Aug 2018, 11:16 +0200, Greg Wilson <gwilson@baosystems.com>, wrote:

Can someone tell me what I am doing wrong here? According to the docs (https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update) this should work to update a user's account:
> curl -X PUT -u "admin:district" -d @u.json -H "Content-Type: application/json" https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge
In this case I am using {"firstName":"ATEST"} as the u.json file. Unfortunately I keep receiving errors such as:
> "Missing required property `surname`."
If I send a more complete user object it complains that I am missing the userCredentials.username property. When I add that, it complains that user already exists.

Gregory Wilson
_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help : https://help.launchpad.net/ListHelp

Thank you Hendrik. PATCH is the way to go for most objects. Unfortunately (per or discussion and here for posterity) it does not currently work with user.userGroupos and user.userCredentials.userRoles. I will need to make a clean copy of the user object and PUT.

···

Gregory Wilson

Hey Greg,

The section of the documentation you included has a reference to the user
object schema, which specifies that for the user object only firstName and
surname are required (/api/schemas/user). I've just tried in 2.27 (not sure
if things changed in 2.29) and this is the minimal package i was able to
use to update the user object:

{
    "id": "Vx7Vgp1I3EK",
    "surname": "Doe",
    "firstName": "John"
}

However, if you include the userCredentials object, you have to include the
id, otherwise it attempts to create a new one and ends up throwing the
already exists. Similarly, /api/schemas/userCredentials has the details
about minimum requirement, and that is username, but as you are doing an
update you have to specify the id as well.

PUT of the entire object with save date and the rest works for me too.

Vlad

···

On Tue, Aug 14, 2018 at 12:17 PM Greg Wilson <gwilson@baosystems.com> wrote:

Thank you Hendrik. PATCH is the way to go for most objects.
Unfortunately (per or discussion and here for posterity) it does not
currently work with user.userGroupos and user.userCredentials.userRoles. I
will need to make a clean copy of the user object and PUT.

*Gregory Wilson*

On Tue, Aug 14, 2018 at 8:16 AM Hendrik de Graaf <hendrik@dhis2.org> > wrote:

Hi Gregory,

For updating a single field on a user record, I would try doing a PATCH
request with exactly the same payload as you were doing.

I do this type of request to disable a user in the User Management app,
so it should work.

Best regards,
Hendrik
On 14 Aug 2018, 11:16 +0200, Greg Wilson <gwilson@baosystems.com>, wrote:

Can someone tell me what I am doing wrong here? According to the docs (
https://docs.dhis2.org/2.29/en/developer/html/dhis2_developer_manual_full.html#webapi_users_create_update)
this should work to update a user's account:

curl -X PUT -u "admin:district" -d @u.json -H "Content-Type:
application/json" https://play.dhis2.org/2.26/api/26/users/DXyJmlo9rge

In this case I am using {"firstName":"ATEST"} as the u.json file.
Unfortunately I keep receiving errors such as:

"Missing required property `surname`."

If I send a more complete user object it complains that I am missing the
userCredentials.username property. When I add that, it complains that user
already exists.

*Gregory Wilson*
_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help : https://help.launchpad.net/ListHelp

_______________________________________________

Mailing list: https://launchpad.net/~dhis2-devs
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help : https://help.launchpad.net/ListHelp

Please also be aware that the User object is very much a “special” type, and does not always follow the rules of other types in the system (dataElements, indicators etc).

I would recommend to be very careful with partial updating of the user object, and instead always use the full payload required (an example full payload can be found in the docs)

···

Morten Olav Hansen

Senior Engineer, DHIS 2

Team Integration Lead

University of Oslo

http://www.dhis2.org