mediatype.create

Description

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.

Parameters

(object/array) Media types to create.

Additionally to the standard media type properties, the method accepts the following parameters.

ParameterTypeDescription
parametersarrayScript or webhook parameters to be created for the media type.
message_templatesarrayMessage templates 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 and message templates.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "mediatype.create",
  4. "params": {
  5. "type": "0",
  6. "name": "E-mail",
  7. "smtp_server": "mail.example.com",
  8. "smtp_helo": "example.com",
  9. "smtp_email": "[email protected]",
  10. "smtp_port": "587",
  11. "content_type": "1",
  12. "message_templates": [
  13. {
  14. "eventsource": "0",
  15. "recovery": "0",
  16. "subject": "Problem: {EVENT.NAME}",
  17. "message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" started at {EVENT.TIME}."
  18. },
  19. {
  20. "eventsource": "0",
  21. "recovery": "1",
  22. "subject": "Resolved in {EVENT.DURATION}: {EVENT.NAME}",
  23. "message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}."
  24. },
  25. {
  26. "eventsource": "0",
  27. "recovery": "2",
  28. "subject": "Updated problem in {EVENT.AGE}: {EVENT.NAME}",
  29. "message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}."
  30. }
  31. ]
  32. },
  33. "id": 1
  34. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "mediatypeids": [
  5. "7"
  6. ]
  7. },
  8. "id": 1
  9. }

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:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "mediatype.create",
  4. "params": {
  5. "type": "1",
  6. "name": "Push notifications",
  7. "exec_path": "push-notification.sh",
  8. "maxattempts": "5",
  9. "attempt_interval": "11s",
  10. "parameters": [
  11. {
  12. "sortorder": "0",
  13. "value": "{ALERT.SENDTO}"
  14. },
  15. {
  16. "sortorder": "1",
  17. "value": "{ALERT.SUBJECT}"
  18. },
  19. {
  20. "sortorder": "2",
  21. "value": "{ALERT.MESSAGE}"
  22. }
  23. ]
  24. },
  25. "id": 1
  26. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "mediatypeids": [
  5. "8"
  6. ]
  7. },
  8. "id": 1
  9. }

Creating a webhook media type

Create a new webhook media type.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "mediatype.create",
  4. "params": {
  5. "type": "4",
  6. "name": "Webhook",
  7. "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}",
  8. "parameters": [
  9. {
  10. "name": "Message",
  11. "value": "{ALERT.MESSAGE}"
  12. },
  13. {
  14. "name": "Subject",
  15. "value": "{ALERT.SUBJECT}"
  16. },
  17. {
  18. "name": "To",
  19. "value": "{ALERT.SENDTO}"
  20. },
  21. {
  22. "name": "Token",
  23. "value": "<Token>"
  24. }
  25. ]
  26. },
  27. "id": 1
  28. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "mediatypeids": [
  5. "9"
  6. ]
  7. },
  8. "id": 1
  9. }

Source

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