Update an existing role
Update role#
To update an existing role record you will need to make a TLS request to the OpenHIM API for the below method and endpoint and supply the updated JSON object for the role record.
Example#
Note: In the examples below, we are using the token authentication type to authenticate requests
- Languages
- Sample Data
Before we can send our request to the OpenHIM API we need to ensure that we construct our valid HTTP headers to successfully authenticate with the OpenHIM API.
- NodeJS
- Bash
Copy the below code at the bottom of your nodejs script that handles the authentication of the OpenHIM headers as described in the authentication section.
Replace the openhimOptions values with the correct implementation details and supply the SampleData payload to submit
Execute the below command in your terminal to run the nodejs script
Ensure that you have created your bash script to construct the HTTP authentication headers and send the request to the OpenHIM API as described in the authentication section.
Execute the below command in your terminal where the file is located with the required arguments. Replace the placeholder arguments with the correct implementation details and ensure your SampleData.json file exists with the updated role object.
The response status code will be 200 if successful.
with a json body containing any updates to channels and clients. As with the create a new role operation, channels and clients can be specified either by their _id or name for a channel and clientID for a client.
Note that the channel and client arrays, if specified, must contain the complete list of items to apply to, i.e. roles will be removed if they exist on any channels and clients that are not contained in the respective arrays. This also means that if channels and clients are specified as empty arrays, the result will be the same as deleting the role. If the fields are not specified, then the existing setup will be left as is.
The following example will change Role1 by giving the clients jembi and client-service permission to access channel1. Any other channels will be removed, e.g. following from the create a new role example, access to channel2 will be removed:
Roles can also be renamed by specifying the name field.