← Back to team overview

dhis2-users team mailing list archive

Re: Web API to get options for a specific optionSet

 

It does.

On Tue, Apr 19, 2016 at 8:07 PM, Iuri Fanti <iuri.fanti@xxxxxxxxx> wrote:

> Wouldn't it be much simpler if the server gave back the id of the
> newly created option as a response?
>
> 2016-04-19 7:10 GMT+02:00 Morten Olav Hansen <morten@xxxxxxxxx>:
> > Hi Luri
> >
> > Probably the best approach to creating new options (and adding to a
> > optionset) is:
> >
> > 1. Create UIDs for every option (/api/system/id?limit=100)
> > 2. Create all your options { "id": "generated-uid", "name":
> "option-name",
> > "code": "option-code" }
> > 3. Add or create your option set { "id": "existing-uid, generated-uid, or
> > null to let the system create", "name": "optionset-name", "valueType":
> > "wanted value type", "options": [your options]
> > 4. Wrap this in the correct payload (see below) and send to /api/metadata
> > with correct content-type (application/json)
> >
> > {
> >   "options": [
> >     { "id": "id1", "name": "Male", "code": "M" },
> >     { "id": "id2", "name": "Female", "code": "F" }
> >   ],
> >   "optionSets": [
> >     {
> >       "id": "id if you have it",
> >       "name": "optionset-name",
> >       "valueType": "optionset-value-type",
> >       "options": [{"id":"id1"},{"id":"id2"}]
> >     }
> >   ]
> > }
> >
> >
> > --
> > Morten Olav Hansen
> > Senior Engineer, DHIS 2
> > University of Oslo
> > http://www.dhis2.org
> >
> > On Tue, Apr 19, 2016 at 8:56 AM, Iuri Fanti <iuri.fanti@xxxxxxxxx>
> wrote:
> >>
> >> Dear Knut,
> >>
> >> I actually read the chapter you linked me, but I couldn't figure out
> >> how to know (referring to your example) that the new option's ID was
> >> UVBgmarFGFb
> >>
> >> Anyway thank you very much for your support!
> >>
> >> iuri
> >>
> >> 2016-04-16 22:34 GMT+02:00 Knut Staring <knutst@xxxxxxxxx>:
> >> > You can first add a new option by creating a simple file like this,
> >> > which I
> >> > called 100years.json:
> >> >
> >> > {
> >> > "name": "Over 100"
> >> > }
> >> >
> >> > Then add it:
> >> > curl -d @100years.json "https://play.dhis2.org/demo/api/options"; -X
> POST
> >> > -H
> >> > "Content-Type: application/json" -u admin:district
> >> >
> >> > Then add the new option to the optionSet:
> >> > curl
> >> >
> >> > "
> https://play.dhis2.org/demo/api/optionSets/VQ2lai3OfVG/options/UVBgmarFGFb
> "
> >> > -X POST -H "Content-Type: application/json" -u admin:district
> >> >
> >> > Finally, inspect the optionSet. It should now have 5 members instead
> of
> >> > 4:
> >> >
> >> >
> https://play.dhis2.org/demo/api/optionSets/VQ2lai3OfVG.json?fields=name,options[:all]
> >> >
> >> >
> >> >
> >> > On Sat, Apr 16, 2016 at 9:51 PM, Knut Staring <knutst@xxxxxxxxx>
> wrote:
> >> >>
> >> >> Hi Luri,
> >> >>
> >> >> Please see section 1.10.4. Adding and removing objects to/from
> >> >> collections
> >> >> here:
> >> >>
> >> >>
> http://dhis2.github.io/dhis2-docs/master/en/developer/html/ch01s10.html
> >> >>
> >> >> Knut
> >> >>
> >> >> On Sat, Apr 16, 2016 at 2:37 AM, Iuri Fanti <iuri.fanti@xxxxxxxxx>
> >> >> wrote:
> >> >>>
> >> >>> And what if I needed to put/create a specific option into a specific
> >> >>> optionSet?
> >> >>>
> >> >>> 2016-04-15 19:46 GMT+02:00 Iuri Fanti <iuri.fanti@xxxxxxxxx>:
> >> >>> > Great Knut, it's exactly what I needed! :)
> >> >>> >
> >> >>> > Thank you so much!
> >> >>> >
> >> >>> > Iuri
> >> >>> >
> >> >>> > 2016-04-15 19:28 GMT+02:00 Knut Staring <knutst@xxxxxxxxx>:
> >> >>> >> Something along these lines?
> >> >>> >>
> >> >>> >>
> >> >>> >>
> >> >>> >>
> https://play.dhis2.org/demo/api/optionSets/VQ2lai3OfVG.json?fields=name,options[:all]
> >> >>> >>
> >> >>> >> On Fri, Apr 15, 2016 at 7:15 PM, Iuri Fanti <
> iuri.fanti@xxxxxxxxx>
> >> >>> >> wrote:
> >> >>> >>>
> >> >>> >>> Hi all,
> >> >>> >>>
> >> >>> >>> is there a Web API call to get the option values for a specific
> >> >>> >>> optionSet? I have a lot of option values, and it's not
> reasonable
> >> >>> >>> to
> >> >>> >>> download all of them. I need to filter by the parent optionSet,
> >> >>> >>> somehow. Is it possibile?
> >> >>> >>>
> >> >>> >>> Thanks,
> >> >>> >>>
> >> >>> >>> Iuri
> >> >>> >>>
> >> >>> >>> --
> >> >>> >>> @-`-,--
> >> >>> >>>
> >> >>> >>> _______________________________________________
> >> >>> >>> Mailing list: https://launchpad.net/~dhis2-users
> >> >>> >>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
> >> >>> >>> Unsubscribe : https://launchpad.net/~dhis2-users
> >> >>> >>> More help   : https://help.launchpad.net/ListHelp
> >> >>> >>
> >> >>> >>
> >> >>> >>
> >> >>> >>
> >> >>> >> --
> >> >>> >> Knut Staring
> >> >>> >> Dept. of Informatics, University of Oslo
> >> >>> >> Norway: +4791880522
> >> >>> >> Skype: knutstar
> >> >>> >> http://dhis2.org
> >> >>> >
> >> >>> >
> >> >>> >
> >> >>> > --
> >> >>> > @-`-,--
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> @-`-,--
> >> >>>
> >> >>> _______________________________________________
> >> >>> Mailing list: https://launchpad.net/~dhis2-users
> >> >>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
> >> >>> Unsubscribe : https://launchpad.net/~dhis2-users
> >> >>> More help   : https://help.launchpad.net/ListHelp
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Knut Staring
> >> >> Dept. of Informatics, University of Oslo
> >> >> Norway: +4791880522
> >> >> Skype: knutstar
> >> >> http://dhis2.org
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > Knut Staring
> >> > Dept. of Informatics, University of Oslo
> >> > Norway: +4791880522
> >> > Skype: knutstar
> >> > http://dhis2.org
> >>
> >>
> >>
> >> --
> >> @-`-,--
> >>
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~dhis2-users
> >> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~dhis2-users
> >> More help   : https://help.launchpad.net/ListHelp
> >
> >
>
>
>
> --
> @-`-,--
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-users
> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-users
> More help   : https://help.launchpad.net/ListHelp
>



-- 
Knut Staring
Dept. of Informatics, University of Oslo
Norway: +4791880522
Skype: knutstar
http://dhis2.org

References