Assigning an Org. Unit Group to a Org. Unit with the API

Hi devs,

So, I am trying to do it in one step (create the org.unit + assign one org. unit group) using the following API call:

http://localhost:8080/dhis/api/organisationUnits

and the payload:

{

“name”:“The name”,

“shortName”:“Short name”,

“parent”:{

“id”:“wSkI02omzoJ”

},

“openingDate”:“2015-03-03”,

“organisationUnitGroups”: [

{“id”:“BW7NafIFfrS”,

“name”:“Project”,

“created”:“2014-11-18T15:56:01.136+0000”,

“lastUpdated”:“2014-11-27T14:20:38.381+0000”}

]

}

However, although the org unit is created and we get a SUCCESS message, the org. unit group is not associated to the org. unit.

Also I tried, in 2 steps (when the org unit is already in the system), something like this:

API: http://localhost:8080/dhis/api/organisationUnitGroups/

{

“id”:“BW7NafIFfrS”,

“organisationUnits”:[{“id”:“Tynta6mhuLQ”}]

}

But nothing happens

Which is the best way to do this?

Thanks

Best regards

Jose

Hi Jose,

I think this was discussed recently here

https://www.mail-archive.com/dhis2-devs@lists.launchpad.net/msg35136.html

Regards,

Jason

···

On Sun, May 3, 2015 at 1:45 AM, Jose Garcia Muñoz josemp10@gmail.com wrote:

Hi devs,

So, I am trying to do it in one step (create the org.unit + assign one org. unit group) using the following API call:

http://localhost:8080/dhis/api/organisationUnits

and the payload:

{

“name”:“The name”,

“shortName”:“Short name”,

“parent”:{

“id”:“wSkI02omzoJ”

},

“openingDate”:“2015-03-03”,

“organisationUnitGroups”: [

{“id”:“BW7NafIFfrS”,

“name”:“Project”,

“created”:“2014-11-18T15:56:01.136+0000”,

“lastUpdated”:“2014-11-27T14:20:38.381+0000”}

]

}

However, although the org unit is created and we get a SUCCESS message, the org. unit group is not associated to the org. unit.

Also I tried, in 2 steps (when the org unit is already in the system), something like this:

API: http://localhost:8080/dhis/api/organisationUnitGroups/

{

“id”:“BW7NafIFfrS”,

“organisationUnits”:[{“id”:“Tynta6mhuLQ”}]

}

But nothing happens

Which is the best way to do this?

Thanks

Best regards

Jose


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

Jason P. Pickering
email: jason.p.pickering@gmail.com
tel:+46764147049

If you can use 2.18 or 2.19, you can use the collection API [1]. If you use 2.18, you -must- use the owning side, which means, add the orgUnit to the orgUnitGroup (and not the other way), in 2.19, you can do both.

[1] https://www.dhis2.org/doc/snapshot/en/developer/html/ch01s08.html#d5e1079

···

On Sun, May 3, 2015 at 12:18 PM, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Jose,

I think this was discussed recently here

https://www.mail-archive.com/dhis2-devs@lists.launchpad.net/msg35136.html

Regards,

Jason


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


Morten

On Sun, May 3, 2015 at 1:45 AM, Jose Garcia Muñoz josemp10@gmail.com wrote:

Hi devs,

So, I am trying to do it in one step (create the org.unit + assign one org. unit group) using the following API call:

http://localhost:8080/dhis/api/organisationUnits

and the payload:

{

“name”:“The name”,

“shortName”:“Short name”,

“parent”:{

“id”:“wSkI02omzoJ”

},

“openingDate”:“2015-03-03”,

“organisationUnitGroups”: [

{“id”:“BW7NafIFfrS”,

“name”:“Project”,

“created”:“2014-11-18T15:56:01.136+0000”,

“lastUpdated”:“2014-11-27T14:20:38.381+0000”}

]

}

However, although the org unit is created and we get a SUCCESS message, the org. unit group is not associated to the org. unit.

Also I tried, in 2 steps (when the org unit is already in the system), something like this:

API: http://localhost:8080/dhis/api/organisationUnitGroups/

{

“id”:“BW7NafIFfrS”,

“organisationUnits”:[{“id”:“Tynta6mhuLQ”}]

}

But nothing happens

Which is the best way to do this?

Thanks

Best regards

Jose


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

Jason P. Pickering
email: jason.p.pickering@gmail.com
tel:+46764147049

Thanks Morten. It worked as you said. It will be nice to test it in 2.19, as now I need to call the API n times if i need to add n orgunitgroups to one orgunit.

Thanks for your quick answer.

···

On Sun, May 3, 2015 at 9:36 AM, Morten Olav Hansen mortenoh@gmail.com wrote:

If you can use 2.18 or 2.19, you can use the collection API [1]. If you use 2.18, you -must- use the owning side, which means, add the orgUnit to the orgUnitGroup (and not the other way), in 2.19, you can do both.

[1] https://www.dhis2.org/doc/snapshot/en/developer/html/ch01s08.html#d5e1079


Morten

On Sun, May 3, 2015 at 12:18 PM, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Jose,

I think this was discussed recently here

https://www.mail-archive.com/dhis2-devs@lists.launchpad.net/msg35136.html

Regards,

Jason


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

On Sun, May 3, 2015 at 1:45 AM, Jose Garcia Muñoz josemp10@gmail.com wrote:

Hi devs,

So, I am trying to do it in one step (create the org.unit + assign one org. unit group) using the following API call:

http://localhost:8080/dhis/api/organisationUnits

and the payload:

{

“name”:“The name”,

“shortName”:“Short name”,

“parent”:{

“id”:“wSkI02omzoJ”

},

“openingDate”:“2015-03-03”,

“organisationUnitGroups”: [

{“id”:“BW7NafIFfrS”,

“name”:“Project”,

“created”:“2014-11-18T15:56:01.136+0000”,

“lastUpdated”:“2014-11-27T14:20:38.381+0000”}

]

}

However, although the org unit is created and we get a SUCCESS message, the org. unit group is not associated to the org. unit.

Also I tried, in 2 steps (when the org unit is already in the system), something like this:

API: http://localhost:8080/dhis/api/organisationUnitGroups/

{

“id”:“BW7NafIFfrS”,

“organisationUnits”:[{“id”:“Tynta6mhuLQ”}]

}

But nothing happens

Which is the best way to do this?

Thanks

Best regards

Jose


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

Jason P. Pickering
email: jason.p.pickering@gmail.com
tel:+46764147049

Dear all

I have a similar issue, I need to add orgunit to an already created group;
creation of the group works via API and the orgunit define during the creation are properly attached but as I cannot have more than 500 in the creation (DHIS2 gives an error above) therefore I need to add the remain one after

Here is the error message I got
dhis2.exceptions.RequestException: code: 409, url: http://localhost:8080/api/organisationUnitGroups?mergeMode=MERGE&importStrategy=CREATE_AND_UPDATE, description: {“httpStatus”:“Conflict”,“httpStatusCode”:409,“status”:“ERROR”,“message”:“One more more errors occurred, please see full details in import report.”,“response”:{“responseType”:“ObjectReport”,“errorReports”:[{“message”:“Found matching object for given reference, but import mode is CREATE. Identifier was UID, and object was Village [TMRPiQT7N4v] (OrganisationUnitGroup).”,“mainKlass”:“org.hisp.dhis.organisationunit.OrganisationUnitGroup”,“errorCode”:“E5000”,“mainId”:“TMRPiQT7N4v”,“errorProperties”:[“UID”,“Village [TMRPiQT7N4v] (OrganisationUnitGroup)”]}],“uid”:“TMRPiQT7N4v”,“klass”:“org.hisp.dhis.organisationunit.OrganisationUnitGroup”}}

What is wierd is that it says “but import mode is CREATE” when I set the import strategy at “CREATE_AND_UPDATE”

here is the structure of the group I sent (again it works when I create the group)

class OrganisationUnitGroup(BaseModel):

created: Optional[datetimeStr]

lastUpdated: Optional[datetimeStr]

id: Optional[uid]

code: Optional[str]

name: str

shortName: Optional[str]

description: Optional[str]

organisationUnits:List[DHIS2Ref] = []

class DHIS2Ref(BaseModel):

id: uid

my setup DHIS2 2.35, Tomcat 8.5, Postgres 11

Any Idea of what I did wrong ?

br

use put method on http://localhost:8080/api/organisationUnitGroups/{groupid}?mergeMode=MERGE&importStrategy=CREATE_AND_UPDATE,

thank but I tried that too,

I solved it by pushing using the metadata ressource instead of organisationUnitGroups. metadata support “addition”/“deletion”

br