Working with the REST API
11 April 2024
ID 204471
Working with MDR through the REST API includes getting, creating, and updating assets, incidents, responses, and users.
The REST API methods require client_id
value. You can get your client_id
value in the Token info block of any refresh token in MDR Web Console.
Following are examples of script for Python and Shell that demonstrate core REST API capabilities:
- Define the certificate path, REST API URL, client ID, and the tokens
- Get access token and refresh token for the next access token update
- Get the number of asset
- Get the list of assets or asset details
- Get the number of incidents, the list of the incidents, or the incident details
- Get the list of responses for the incident
- Confirm, decline the response, or update the response list
- Get the list of comments for the specified incident, or create a new comment for the specified incident
Example (Python):
|
Example (Shell):
|
REST API reply example with the access token and new refresh token:
{
"access_token": "SamPLET346yoKEnSamPLEToK25EnSamPLEToK35EnS",
"refresh_token": "tOKenSaMPlet259OKenS123aMPle926tOKenSaMPle"
}
REST API reply example with the structure and values of comments:
[{
"comment_id": "bfu6TiNghqp",
"author_name": "John Doe",
"text": "<p>
The first comment.
</p>",
"creation_time": 1601295428640
}, {
"comment_id": "bfu6TiNghqt",
"author_name": "Jane Doe",
"text": "<p>
The second comment.
</p>",
"creation_time": 1601295433441
}]
REST API reply example when REST API creates a new comment and sends a response with the comment details:
{
"comment_id": "AXTej0Qi4bfu6TiNgmvT",
"author_name": "Token name",
"text": "
This is a new comment created via the REST API.
",
"creation_time": 1601461748122
}