object mediatype.create(object/array mediaTypes)
This method allows to create new media types.
(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. |
(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.
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"
},
"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.