object mediatype.create(object/array mediaTypes)
This method allows to create new media types.
This method is only available to Super admin user type. Permissions to call the method can be revoked in user role settings. See User roles for more information.
(object/array)
Media types to create.
Additionaly to the standard media type properties, the method accepts the following parameters.
Parameter | Type | Description |
---|---|---|
parameters | array | Webhook parameters to be created for the media type. |
message_templates | array | Message templates to be created for the media type. |
(object)
Returns an object containing the IDs of the created media types under the mediatypeids
property. The order of the returned IDs matches the order of the passed media types.
Create a new e-mail media type with a custom SMTP port and message templates.
Request:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "0",
"name": "E-mail",
"smtp_server": "mail.example.com",
"smtp_helo": "example.com",
"smtp_email": "[email protected]",
"smtp_port": "587",
"content_type": "1",
"message_templates": [
{
"eventsource": "0",
"recovery": "0",
"subject": "Problem: {EVENT.NAME}",
"message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" started at {EVENT.TIME}."
},
{
"eventsource": "0",
"recovery": "1",
"subject": "Resolved in {EVENT.DURATION}: {EVENT.NAME}",
"message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}."
},
{
"eventsource": "0",
"recovery": "2",
"subject": "Updated problem in {EVENT.AGE}: {EVENT.NAME}",
"message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}."
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Create a new script media type with a custom value for the number of attempts and the interval between them.
Request:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "1",
"name": "Push notifications",
"exec_path": "push-notification.sh",
"exec_params": "{ALERT.SENDTO}\n{ALERT.SUBJECT}\n{ALERT.MESSAGE}\n",
"maxattempts": "5",
"attempt_interval": "11s"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Create a new webhook media type.
Request:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "4",
"name": "Webhook",
"script": "var Webhook = {\r\n token: null,\r\n to: null,\r\n subject: null,\r\n message: null,\r\n\r\n sendMessage: function() {\r\n // some logic\r\n }\r\n}",
"parameters": [
{
"name": "Message",
"value": "{ALERT.MESSAGE}"
},
{
"name": "Subject",
"value": "{ALERT.SUBJECT}"
},
{
"name": "To",
"value": "{ALERT.SENDTO}"
},
{
"name": "Token",
"value": "<Token>"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
CMediaType::create() in ui/include/classes/api/services/CMediaType.php.