← Back to team overview

dhis2-devs team mailing list archive

Re: Assigning org unit to program via API

 

Hi

What version of dhis are you using? and what revision? there have been
changes to this in 2.16 vs trunk, which can cause issues like that (your db
will only be valid with either 2.16 or trunk, you can't switch between them)

Also make sure that you are using newest trunk or newest 2.16, since there
have been updates related to program in the last few days

--
Morten


On Tue, Aug 26, 2014 at 5:08 PM, Mahendra Kariya <
mahendra.kariya@xxxxxxxxxxxxxxxx> wrote:

> Thanks for the prompt reply Morten!
>
> But when we are trying to PUT the object to /api/programs/id, we are
> getting null constraint violation for sort_order column. The payload that
> we are PUTting is below. (We simply added one more org unit to the response
> that we received from GET.)
>
> {
>   "id": "adb81a4bc13",
>   "created": "2014-08-26T05:59:08.835+0000",
>   "name": "ABCD",
>   "href": "http://localhost:8080/api/programs/adb81a4bc13";,
>   "lastUpdated": "2014-08-26T08:50:39.622+0000",
>   "type": 3,
>   "kind": "SINGLE_EVENT_WITHOUT_REGISTRATION",
>   "version": 1,
>   "description": "ABCD",
>   "onlyEnrollOnce": false,
>   "externalAccess": false,
>   "displayIncidentDate": true,
>   "dateOfIncidentDescription": "Incident Date",
>   "displayOnAllOrgunit": true,
>   "publicAccess": "rw------",
>   "registration": false,
>   "selectEnrollmentDatesInFuture": false,
>   "dataEntryMethod": false,
>   "singleEvent": true,
>   "ignoreOverdueEvents": false,
>   "relationshipFromA": false,
>   "displayName": "ABCD",
>   "selectIncidentDatesInFuture": false,
>   "access": {
>     "update": true,
>     "externalize": false,
>     "delete": true,
>     "write": true,
>     "read": true,
>     "manage": true
>   },
>   "user": {
>     "id": "SZ3QccaOLXH",
>     "name": "admin admin",
>     "created": "2014-08-26T05:58:00.992+0000",
>     "lastUpdated": "2014-08-26T05:59:12.686+0000"
>   },
>   "validationCriterias": [],
>   "programStages": [
>     {
>       "id": "a29be1d359a",
>       "name": "ABCD Stage",
>       "created": "2014-08-26T05:59:08.903+0000",
>       "lastUpdated": "2014-08-26T05:59:10.896+0000"
>     }
>   ],
>   "instanceReminders": [],
>   "organisationUnits": [
>     {
>       "id": "b876de81d4e",
>       "name": "A Test Country",
>       "created": "2014-06-13T05:11:18.804+0000",
>       "lastUpdated": "2014-08-26T05:58:58.563+0000"
>     },
>     {
>       "id": "a2cf79e8f13",
>       "name": "Aother Test Country",
>       "created": "2014-06-13T05:11:18.804+0000",
>       "lastUpdated": "2014-08-26T05:58:58.563+0000"
>     },
>     {
>     "id": "a420aa7ff4d"
>     }
>   ],
>   "programTrackedEntityAttributes": [],
>   "userRoles": [
>     {
>       "id": "Sd32f0f1336",
>       "name": "user1",
>       "created": "2014-06-13T05:11:18.804+0000",
>       "lastUpdated": "2014-08-26T05:58:58.563+0000"
>     },
>     {
>       "id": "N3f8TR7HAZS",
>       "name": "Superuser",
>       "created": "2014-06-13T05:10:15.913+0000",
>       "lastUpdated": "2014-08-26T05:58:58.595+0000"
>     }
>   ],
>   "userGroupAccesses": []
> }
>
>
>
> Thanks,
> Mahendra
> *Thought*Works
>
>
> On Tue, Aug 26, 2014 at 2:50 PM, Morten Olav Hansen <mortenoh@xxxxxxxxx>
> wrote:
>
>> Hi Mahendra
>>
>> If you want to update a program, you need to use a PUT request to the
>> /api/programs/id
>>
>> It's saying "Object already exists" because the uid already exists in
>> the system.
>>
>> Btw, you need to send the full payload, we don't support partial updates.
>>
>> --
>> Morten
>>
>>
>> On Tue, Aug 26, 2014 at 4:06 PM, Mahendra Kariya <
>> mahendra.kariya@xxxxxxxxxxxxxxxx> wrote:
>>
>>> Hi,
>>>
>>> We are trying to assign org units to an existing Program via web api.
>>>
>>> We tried the posting the below payload to /api/programs, but it is
>>> throwing an error "Object already exists".
>>>
>>> {
>>>   "id": "adb81a4bc13"
>>>   "organisationUnits": [
>>>     {
>>>       "id": "a2cf79e8f13"
>>>     },
>>>     {
>>>       "id": "b876de81d4e"
>>>     }
>>>   ]
>>> }
>>>
>>> We tried posting the following payload to /api/metadata, but it is
>>> throwing constraint violation error.
>>>  {
>>>   "programs": [
>>>     {
>>>       "id": "adb81a4bc13",
>>>       "organisationUnits": [
>>>         {
>>>           "id": "a2cf79e8f13"
>>>         },
>>>         {
>>>           "id": "b876de81d4e"
>>>         }
>>>       ]
>>>     }
>>>   ]
>>> }
>>>
>>> Could you guys point us to the correct payload format?
>>>
>>>
>>> Thanks,
>>> Mahendra
>>> *Thought*Works
>>>
>>
>>
>

References