LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • Sending
  • Legacy
  • send(name, variables, options)
  • send(payload, options)

Was this helpful?

  1. Cortex API
  2. Scripting

Notifications

Notifications may be sent from a script.

Sending

import notifications from 'notifications'

Define custom endpoints:

return notifications.send('c_axon_leave_study', {
  var1: 'test1',
  var2: 'test2'
}, {
  endpoints: {
    push: {
      template: 'message as template {{var1}}',
      apn: {
        topics: [
          'app',
          'voip'
        ]
      }
    }
  }
})

Define custom HTML:

return notifications.send('c_axon_leave_study', {}, {
  endpoints: {
    email: {
      recipient: 'valid@example.com',
      template: null,
      message: 'testing',
      html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
    }
  }
})

Send a predefined notification:

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  notification: 'c_test_not'
})

Send an empty notification:

import constants from 'constants'

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  notification: constants.emptyId,
  endpoints: {
    email: {
      template: null,
      message: 'testing',
      html: '<html></html>'
    }
  }
})

Send a notification without a template or that is not predefined:

return notifications.send({
  var1: 'test1',
  var2: 'test2'
}, {
  endpoints: {
    push: {
      message: 'test',
      apn: {
        topics: apnsTopics
      }
    }
  }
})

Send a Short Message Service (SMS) request to a custom mobile number using an existing template:

return notifications.send({ age: '32' }, {
  endpoints: {
    sms: {
      template: 'c_sms_template',
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a custom mobile number without a template:

return notifications.send({}, {
  endpoints: {
    sms: {
      message: 'Medable rocks!',
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a custom mobile number without a template (example 2):

return notifications.send('Medable rocks!', {}, {
  endpoints: {
    sms: {
      mobile: '+18004444444'
    }
  }
})

Send an SMS to a recipient without a template:

return notifications.send('Medable rocks!', {}, {
  endpoints: {
    sms: {}
  },
  recipient: 'valid@example.com'
})

Push a mobile notification to a recipient using an existing template:

return notifications.send({
  text1: 'Medable rocks!'
}, {
  endpoints: {
    push: {
      template: 'c_push_test',
      apn: {
        topics: ['app'],
        pushType: 'alert'
      }
    }
  },
  recipient: 'valid@example.com'
})

Push a mobile notification to a recipient using an existing template:

return notifications.send({}, {
  endpoints: {
    push: {
      message: 'Medable rocks!',
      apn: {
        topics: ['app'],
        pushType: 'alert'
      }
    }
  }
  recipient: 'valid@example.com'
})

Send an email using an existing template:

return notifications.send({
  name: 'Adam',
  email: 'valid@example.com'
  account_id: '12345',
  study_name: 'Study',
  study_code: '00001',
  study_id: '12345'
}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      template: 'c_axon_leave_study'
    }
  }
})

Send an email with HTML and no template:

return notifications.send({}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      subject: 'Medable',
      html: '<html><p>Medable&nbsp;rocks&#33;<p></html>'
    }
  }
})

Send an email with a plain message and no template:

return notifications.send({}, {
  endpoints: {
    email: {
      recipients: [
        'valid1@example.com',
        'valid2@example.com'
      ],
      subject: 'Medable',
      message: 'Medable rocks!'
    }
  }
})

Legacy

const payload = {
  var1: 'test1',
  var2: 'test2'
}

notifications.send('c_axon_leave_study', payload)

notifications.send('c_axon_leave_study', payload, {
  apnsTopics: [
    'app',
    'voip'
  ],
  fcmTopic: 'all-devices',
  recipient: 'valid@example.com'
})

return

send(name, variables, options)

Arguments

  • name { String } Notification name

  • variables { Object } Variables to be used in templates

  • options { Object } [Optional]

    • number { String } Sender number

    • recipient { ObjectID, String } ObjectID from account or email

    • context { Object }

    • locale { String } For example, 'en_US'

    • apiKey { String }

    • count { Number } If set, sets the badge on the device icon

    • sound { String } If provided, overrides the default sound

    • apnTopics { String [] }

    • fcmTopic { String [] }

    • pushType { String } Applies only for Apple Push Notification (APN)

send(payload, options)

Arguments

  • payload { Object | String | Number } In case of string, used as payload only; if not, starts with c_ or __ or not in system notification names

  • options { Object } [Optional]

    • context { Object }

    • locale { String } For example, 'en_US'

    • apiKey { String }

    • endpoints { Object }

      • email { Object }

        • recipient { ObjectID | String } ObjectID from account or email

        • template { String }

        • message { String } Plain text message

        • html { String } HTML message

      • push { Object }

        • template { String }

        • message { String }

          • apn { Object }

            • topics { String [] }

            • pushType { String }

          • fcm { Object }

            • topic { String }

          • tpns { Object }

      • sms { Object }

        • mobile { String } Recipient phone number

        • number { String } Sender number

        • message { String }

Last updated 3 years ago

Was this helpful?

View for more information about Tencent API push notifications.

Tencent Push Notification Service (TPNS)