Setting owner of object with API

Hi devs,
I’m trying to set the owner of an object using the API (using PATCH), but it fails.

Example (agains /demo):

curl -X PATCH -H «Content-Type: application/json" -u admin:district -d ‘{ “user”: { “id”: “dXKBEMfyChY” } }’ “https://play.dhis2.org/demo/api/dataSets/kS1CX1YBcl1/user” -v

Result:

{«httpStatus":“Internal Server Error”,“httpStatusCode”:500,“status”:“ERROR”,“message”:“object references an unsaved transient instance - save the transient instance before flushing: org.hisp.dhis.user.User”}

Is this a bug, or have I misunderstood how to do this?

Regards

Olav

Hey Olav,

PATCH doesn’t really work for object references. You can try to download the whole object and PUT it back :wink:

So basically GET → https://play.dhis2.org/demo/api/dataSets/lyLU2wR22tC.json?fields=:owner

Change user id on the returned object.

Then PUT that payload back to → https://play.dhis2.org/demo/api/dataSets/lyLU2wR22tC.json

···

On Wed, Feb 8, 2017 at 10:01 AM, Olav Poppe olav.poppe@me.com wrote:

Hi devs,
I’m trying to set the owner of an object using the API (using PATCH), but it fails.

Example (agains /demo):

curl -X PATCH -H «Content-Type: application/json" -u admin:district -d ‘{ “user”: { “id”: “dXKBEMfyChY” } }’ “https://play.dhis2.org/demo/api/dataSets/kS1CX1YBcl1/user” -v

Result:

{«httpStatus":“Internal Server Error”,“httpStatusCode”:500,“status”:“ERROR”,“message”:“object references an unsaved transient instance - save the transient instance before flushing: org.hisp.dhis.user.User”}

Is this a bug, or have I misunderstood how to do this?

Regards

Olav


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

Regards,

Mark Polak

Software developer, DHIS 2

University of Oslo

http://www.dhis2.org

mark@dhis2.org

Okay, thanks!

Olav

···

On Wed, Feb 8, 2017 at 10:01 AM, Olav Poppe olav.poppe@me.com wrote:

Hi devs,
I’m trying to set the owner of an object using the API (using PATCH), but it fails.

Example (agains /demo):

curl -X PATCH -H «Content-Type: application/json" -u admin:district -d ‘{ “user”: { “id”: “dXKBEMfyChY” } }’ “https://play.dhis2.org/demo/api/dataSets/kS1CX1YBcl1/user” -v

Result:

{«httpStatus":“Internal Server Error”,“httpStatusCode”:500,“status”:“ERROR”,“message”:“object references an unsaved transient instance - save the transient instance before flushing: org.hisp.dhis.user.User”}

Is this a bug, or have I misunderstood how to do this?

Regards

Olav


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

Regards,

Mark Polak

Software developer, DHIS 2

University of Oslo

http://www.dhis2.org

mark@dhis2.org

Any thing new with PATCH?