How to interact with the OpenSRP settings endpoint

Features

  • Allows fetching of global settings

    • These are settings not attached to a team, teamId, location & provider

  • Allows the resolution of settings per location.

    • In case we have different locations with settings, we could easily fetch all the settings for a specific location in a hierarchy and also display all extra settings in the whole hierarchy as part of this same payload.

    • A locationId must be provided as a parameter

Key additions on client core

  • Added the ability to fetch global settings

    • Override the hasGlobalSettings() function and set it as false to deactivate the fetching of global settings.

      @Override public boolean hasGlobalSettings() { return false; }

  • Added the ability to resolve settings

    • Add true param resolve=true to the settings get endpoint.

      • The locationId param will be required for this to work.

  • Added the ability to define different sync filters for settings

    • Instead of using the default sync filter as a parameter for syncing/fetching settings we can now define additional filters.

      • Override the hasExtraSettingsSync() function and set it as true to activate the additional sync filters.

        @Override public boolean hasExtraSettingsSync() { return true; }
      • Override the getExtraSettingsParameters and define your sync filters as shown in the example below

      • @Override public List<String> getExtraSettingsParameters() { AllSharedPreferences sharedPreferences = AncLibrary.getInstance().getContext().userService().getAllSharedPreferences(); String providerId = sharedPreferences.fetchRegisteredANM(); List<String> params = new ArrayList<>(); params.add(ConstantsUtils.SettingsSyncParams.LOCATION_ID + "=" + sharedPreferences.fetchDefaultLocalityId(providerId)); return params; }

         

        • NB : - All the methods mentioned above are on the SyncConfiguration class

V1 settings endpoint

V1 GET global settings
https://<opensrp-server>/rest/settings/sync?serverVersion=0

V1 GET settings without resolving
https://<opensrp-server>/rest/settings/sync?teamId=<team-uuid>&serverVersion=0

V1 GET settings with resolving
https://<opensrp-server>/rest/settings/sync?teamId=<team-uuid>&locationId=<location-uuid>&serverVersion=0&resolve=true
For resolving to work the current user logged in location has to be provided. This helps us get the location hierarchy in which to look for setting before resolving.

V1 POST settings
https://<opensrp-server>/rest/settings/sync

Sample payload

V1 PUT settings
https://<opensrp-server>/rest/settings/sync

Sample payload

V2 settings endpoint

V2 GET global settings
https://<opensrp-server>/rest/v2/settings/?serverVersion=0

V2 GET without resolving setitngs
https://<opensrp-server>/rest/v2/settings/?teamId=<team-uuid>&serverVersion=0

V2 GET settings with location resolving
https://<opensrp-server>/rest/v2/settings/?teamId=<team-uuid>&serverVersion=0&locationId=<location-uuid>&resolve=true

V2 POST settings
https://<opensrp-server>/rest/v2/settings
Sample payload attached

The settingsId is the Id of the setting you would like this to be saved against. If its a new setting that doesn't have any set it belongs to created then do away with the settingsId property
- this can be found in the payloads returned by the GET endpoints
- in V1 its the _id e.g "_id": "20c89e10-a358-41c4-9062-9bd0eeb32c94"
- in V2 its the "documentId": "20c89e10-a358-41c4-9062-9bd0eeb32c94"

The locationId id is the Id of the location you would like this to be saved against. If its a new setting that doesn't have any location it belongs to then do away with the locationId property

V2 PUT settings
https://<opensrp-server>/rest/v2/settings/<id> - <id> parameter is the _id in the setting payload.
Sample payload attached

The settingsId is exactly as explained above
The locationId is exactly as explained above
The uuid is the unique id for the settings. Its found in the property uuid in both the V1 & V2 endpoints.
The _id is the setting metadata id
- its named settingMetadataId in both V1 & v2 endpoints e.g "settingMetadataId": "1"
The identifier is the unique name the user assigns the settings on creation
- its named identifier & settingIdentifier in the v1 endpoint
- its named settingIdentifier in the v2 endpoint
The teamId is the id of the team that this settings belongs to. It can be added on both the POST & PUT payload if required
The team is the name of the team that this settings belongs to. It can be added on both the POST & PUT payload if required

V2 DELETE settings
https://<opensrp-server>/rest/v2/settings/<id> – where the id is the settingsMetadataId