Download DHIS2 Developer Manual

Transcript
Web API
Managing messages
"id": "N3PZBUlN8vq"
}
],
"userGroups": [
{
"id": "ZoHNWQajIoe"
}
],
"organisationUnits": [
{
"id": "DiszpKrYNg8"
}
]
}
curl -d @message.json "https://play.dhis2.org/demo/api/messageConversations" -H
"Content-Type:application/json" -u admin:district -X POST -v
If all is well we receive a 201 Created HTTP status code. Also note that we receive a Location HTTP header which
value informs us of the URL of the newly created message conversation resource - this can be used by a consumer
to perform further action.
We will now pretend to be the mobile user and read te message which was just sent by dispatching a GET request to
the messageConversations resource. We supply an Accept header with application/xml as the value to indicate that we
are interested in the XML resource representation and we authenticate as the mobile user:
curl "https://play.dhis2.org/demo/api/messageConversations" -H "Accept:application/
xml" -u mobile:district -X GET -v
In response we get the following XML:
<messageConversations xmlns="http://dhis2.org/schema/dxf/2.0"
link="https://play.dhis2.org/demo/api/messageConversations">
<messageConversation name="Mortality data reporting" id="ZjHHSjyyeJ2"
link="https://play.dhis2.org/demo/api/messageConversations/ZjHHSjyyeJ2"/>
<messageConversation name="DHIS version 2.7 is deployed" id="GDBqVfkmnp2"
link="https://play.dhis2.org/demo/api/messageConversations/GDBqVfkmnp2"/>
</messageConversations>
From the response we are able to read the identifier of the newly sent message which is ZjHHSjyyeJ2. Note that the
link to the specific resource is embedded and can be followed in order to read the full message. From the description
at http://play.dhis2.org/demo/api/messageConversations we learned that we can reply directly to an existing message
conversation once we know the URL by including the message text as the request payload (body). We are now able
to construct a URL for sending our reply:
curl -d "Yes the Mortality data set has been reported" "https://play.dhis2.org/demo/
api/messageConversations/ZjHHSjyyeJ2" -H "Content-Type:text/plain" -u mobile:district
-X POST -v
If all went according to plan you will receive a 200 OK status code.
1.21.2. Managing messages
Note: the Web-API calls discussed in this section were introduced in DHIS 2.17
As users receive and send messages, conversations will start to pile up in their inboxes, eventually becoming laborious
to track. We will now have a look at managing a users message inbox by removing and marking conversations through
the Web-API. We will do so by performing some maintenance in the inbox of the DHIS Administrator user.
First, let's have a look at removing a few messages from the inbox. Be sure to note that all removal operations described
here only remove the relation between a user and a message conversation. In practical terms this means that we are not
43