This is the documentation page for an unsupported version of Zabbix.
Is this not what you were looking for? Switch to the current version or choose one from the drop-down menu.

mediatype.create

Description

object mediatype.create(object/array mediaTypes)

This method allows to create new media types.

Parameters

(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.

Return values

(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.

Examples

Creating an e-mail media type

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:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "7"
               ]
           },
           "id": 1
       }

Creating a script media type

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:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "8"
               ]
           },
           "id": 1
       }

Creating a webhook media type

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:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "9"
               ]
           },
           "id": 1
       }

Source

CMediaType::create() in ui/include/classes/api/services/CMediaType.php.