1.79 User data store

In addition to the dataStore which is shared between all users of the system, a user-based data store is also available. Data stored to the userDataStore is associated with individual users, so that each user can have different data on the same namespace and key combination. All calls against the userDataStore will be associated with the logged in user. This means one can only see, change, remove and add values associated with the currently logged in user.

/api/26/userDataStore

1.79.1 User data store structure

userDataStore consists of a user, a namespace, keys and associated values. The combination of user, namespace and key is unique.

User data store structure
Item Description Data Type
User The user this data is associated with String
Namespace The namespace the key belongs to String
Key The key a value is stored on String
Value The value stored JSON
Encrypted Indicates whether the value should be encrypted Boolean

1.79.2 Get namespaces

Returns an array of all existing namespaces

GET /api/26/userDataStore

Example request:

curl -X GET -H "Content-Type: application/json" -u admin:district "play.dhis2.org/api/26/userDataStore" -v

[
  "foo",
  "bar"
]

1.79.3 Get keys

Returns an array of all existing keys in a given namespace

GET /api/userDataStore/<namespace>

Example request:

curl -X GET -H "Content-Type: application/json" -u admin:district "play.dhis2.org/api/26/userDataStore/foo" -v

[
  "key_1",
  "key_2"
]

1.79.4 Get values

Returns the value for a given namespace and key

GET /api/26/userDataStore/<namespace>/<key>

Example request:

curl -X GET -H "Content-Type: application/json" -u admin:district "play.dhis2.org/api/26/userDataStore/foo/bar"

{
  "some": "value"
}

1.79.5 Create value

Adds a new value to a given key in a given namespace.

POST /api/26/userDataStore/<namespace>/<key>

Example request:

curl -X POST -H "Content-Type: application/json" -u admin:district -d "['some value']"
  "play.dhis2.org/api/26/userDataStore/foo/bar"

{
  "httpStatus": "Created",
  "httpStatusCode": 201,
  "status": "OK",
  "message": "Key 'bar' in namespace 'foo' created."
}

If you require the value to be encrypted (For example user credetials and such) you can append a query to the url like this:

GET /api/26/userDataStore/<namespace>/<key>?encrypt=true

1.79.6 Update values

Updates an existing value

PUT /api/26/userDataStore/<namespace>/<key>

Example request:

curl -X PUT -H "Content-Type: application/json" -u admin:district -d "['new value']"
  "play.dhis2.org/api/26/userDataStore/foo/bar"

{
  "httpStatus":"Created",
  "httpStatusCode":201,
  "status":"OK",
  "message":"Key 'bar' in namespace 'foo' updated."
}

1.79.7 Delete key

Delete a key

DELETE /api/26/userDataStore/<namespace>/<key>

Example request:

curl -X DELETE -u admin:district "play.dhis2.org/api/26/userDataStore/foo/bar"

{
  "httpStatus":"OK",
  "httpStatusCode":200,
  "status":"OK",
  "message":"Key 'bar' deleted from the namespace 'foo."
}

1.79.8 Delete namespace

Delete all keys in the given namespace

DELETE /api/26/userDataStore/<namespace>

Example request:

curl -X DELETE -u admin:district "play.dhis2.org/api/26/userDataStore/foo"

{
  "httpStatus":"OK",
  "httpStatusCode":200,
  "status":"OK",
  "message":"All keys from namespace 'foo' deleted."
}