Create notification

POST /v1/Services/{ServiceSid}/Notifications

Path parameters

  • ServiceSid string Required

    The SID of the Service to create the resource under.

    Minimum length is 34, maximum length is 34. Format should match the following pattern: ^IS[0-9a-fA-F]{32}$.

application/x-www-form-urlencoded

Body

  • Body string

    The notification text. For FCM and GCM, translates to data.twi_body. For APNS, translates to aps.alert.body. For SMS, translates to body. SMS requires either this body value, or media_urls attribute defined in the sms parameter of the notification.

  • Priority string

    The priority of the notification. Can be: low or high and the default is high. A value of low optimizes the client app's battery consumption; however, notifications may be delivered with unspecified delay. For FCM and GCM, low priority is the same as Normal priority. For APNS low priority is the same as 5. A value of high sends the notification immediately, and can wake up a sleeping device. For FCM and GCM, high is the same as High priority. For APNS, high is a priority 10. SMS does not support this property.

    Values are high or low.

  • Ttl integer

    How long, in seconds, the notification is valid. Can be an integer between 0 and 2,419,200, which is 4 weeks, the default and the maximum supported time to live (TTL). Delivery should be attempted if the device is offline until the TTL elapses. Zero means that the notification delivery is attempted immediately, only once, and is not stored for future delivery. SMS does not support this property.

  • Title string

    The notification title. For FCM and GCM, this translates to the data.twi_title value. For APNS, this translates to the aps.alert.title value. SMS does not support this property. This field is not visible on iOS phones and tablets but appears on Apple Watch and Android devices.

  • Sound string

    The name of the sound to be played for the notification. For FCM and GCM, this Translates to data.twi_sound. For APNS, this translates to aps.sound. SMS does not support this property.

  • Action string

    The actions to display for the notification. For APNS, translates to the aps.category value. For GCM, translates to the data.twi_action value. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

  • Data

    The custom key-value pairs of the notification's payload. For FCM and GCM, this value translates to data in the FCM and GCM payloads. FCM and GCM reserve certain keys that cannot be used in those channels. For APNS, attributes of data are inserted into the APNS payload as custom properties outside of the aps dictionary. In all channels, we reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed and are rejected as 400 Bad request with no delivery attempted. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

  • Apn

    The APNS-specific payload that overrides corresponding attributes in the generic payload for APNS Bindings. This property maps to the APNS Payload item, therefore the aps key must be used to change standard attributes. Adds custom key-value pairs to the root of the dictionary. See the APNS documentation for more details. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed.

  • Gcm

    The GCM-specific payload that overrides corresponding attributes in the generic payload for GCM Bindings. This property maps to the root JSON dictionary. See the GCM documentation for more details. Target parameters to, registration_ids, and notification_key are not allowed. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed. GCM also reserves certain keys.

  • Sms

    The SMS-specific payload that overrides corresponding attributes in the generic payload for SMS Bindings. Each attribute in this value maps to the corresponding form parameter of the Twilio Message resource. These parameters of the Message resource are supported in snake case format: body, media_urls, status_callback, and max_price. The status_callback parameter overrides the corresponding parameter in the messaging service, if configured. The media_urls property expects a JSON array.

  • FacebookMessenger

    Deprecated.

  • Fcm

    The FCM-specific payload that overrides corresponding attributes in the generic payload for FCM Bindings. This property maps to the root JSON dictionary. See the FCM documentation for more details. Target parameters to, registration_ids, condition, and notification_key are not allowed in this parameter. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed. FCM also reserves certain keys, which cannot be used in that channel.

  • Segment array[string]

    The Segment resource is deprecated. Use the tag parameter, instead.

  • Alexa

    Deprecated.

  • ToBinding array[string]

    The destination address specified as a JSON string. Multiple to_binding parameters can be included but the total size of the request entity should not exceed 1MB. This is typically sufficient for 10,000 phone numbers.

  • DeliveryCallbackUrl string

    URL to send webhooks.

  • Identity array[string]

    The identity value that uniquely identifies the new resource's User within the Service. Delivery will be attempted only to Bindings with an Identity in this list. No more than 20 items are allowed in this list.

  • Tag array[string]

    A tag that selects the Bindings to notify. Repeat this parameter to specify more than one tag, up to a total of 5 tags. The implicit tag all is available to notify all Bindings in a Service instance. Similarly, the implicit tags apn, fcm, gcm, sms and facebook-messenger are available to notify all Bindings in a specific channel.

Responses

  • 201 application/json

    Created

    Hide headers attributes Show headers attributes
    • Access-Control-Allow-Origin string

      Specify the origin(s) allowed to access the resource

    • Access-Control-Allow-Methods string

      Specify the HTTP methods allowed when accessing the resource

    • Access-Control-Allow-Headers string

      Specify the headers allowed when accessing the resource

    • Access-Control-Allow-Credentials boolean

      Indicates whether the browser should include credentials

    • Access-Control-Expose-Headers string

      Headers exposed to the client

    Hide response attributes Show response attributes object
    • sid string | null

      The unique string that we created to identify the Notification resource.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^NT[0-9a-fA-F]{32}$.

    • account_sid string | null

      The SID of the Account that created the Notification resource.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^AC[0-9a-fA-F]{32}$.

    • service_sid string | null

      The SID of the Service the resource is associated with.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^IS[0-9a-fA-F]{32}$.

    • date_created string(date-time) | null

      The date and time in GMT when the resource was created specified in RFC 2822 format.

    • identities array[string] | null

      The list of identity values of the Users to notify. We will attempt to deliver notifications only to Bindings with an identity in this list.

    • tags array[string] | null

      The tags that select the Bindings to notify. Notifications will be attempted only to Bindings that have all of the tags listed in this property.

    • segments array[string] | null

      The list of Segments to notify. The Segment resource is deprecated. Use the tags property, instead.

    • priority string

      The priority of the notification. Can be: low or high and the default is high. A value of low optimizes the client app's battery consumption; however, notifications may be delivered with unspecified delay. For FCM and GCM, low priority is the same as Normal priority. For APNS low priority is the same as 5. A value of high sends the notification immediately, and can wake up a sleeping device. For FCM and GCM, high is the same as High priority. For APNS, high is a priority 10. SMS does not support this property.

      Values are high or low.

    • ttl integer

      How long, in seconds, the notification is valid. Can be an integer between 0 and 2,419,200, which is 4 weeks, the default and the maximum supported time to live (TTL). Delivery should be attempted if the device is offline until the TTL elapses. Zero means that the notification delivery is attempted immediately, only once, and is not stored for future delivery. SMS does not support this property.

      Default value is 0.

    • title string | null

      The notification title. For FCM and GCM, this translates to the data.twi_title value. For APNS, this translates to the aps.alert.title value. SMS does not support this property. This field is not visible on iOS phones and tablets but appears on Apple Watch and Android devices.

    • body string | null

      The notification text. For FCM and GCM, translates to data.twi_body. For APNS, translates to aps.alert.body. For SMS, translates to body. SMS requires either this body value, or media_urls attribute defined in the sms parameter of the notification.

    • sound string | null

      The name of the sound to be played for the notification. For FCM and GCM, this Translates to data.twi_sound. For APNS, this translates to aps.sound. SMS does not support this property.

    • action string | null

      The actions to display for the notification. For APNS, translates to the aps.category value. For GCM, translates to the data.twi_action value. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

    • data

      The custom key-value pairs of the notification's payload. For FCM and GCM, this value translates to data in the FCM and GCM payloads. FCM and GCM reserve certain keys that cannot be used in those channels. For APNS, attributes of data are inserted into the APNS payload as custom properties outside of the aps dictionary. In all channels, we reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed and are rejected as 400 Bad request with no delivery attempted. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

    • apn

      The APNS-specific payload that overrides corresponding attributes in the generic payload for APNS Bindings. This property maps to the APNS Payload item, therefore the aps key must be used to change standard attributes. Adds custom key-value pairs to the root of the dictionary. See the APNS documentation for more details. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed.

    • gcm

      The GCM-specific payload that overrides corresponding attributes in the generic payload for GCM Bindings. This property maps to the root JSON dictionary. Target parameters to, registration_ids, and notification_key are not allowed. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed.

    • fcm

      The FCM-specific payload that overrides corresponding attributes in the generic payload for FCM Bindings. This property maps to the root JSON dictionary. See the FCM documentation for more details. Target parameters to, registration_ids, condition, and notification_key are not allowed in this parameter. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed. FCM also reserves certain keys, which cannot be used in that channel.

    • sms

      The SMS-specific payload that overrides corresponding attributes in the generic payload for SMS Bindings. Each attribute in this value maps to the corresponding form parameter of the Twilio Message resource. These parameters of the Message resource are supported in snake case format: body, media_urls, status_callback, and max_price. The status_callback parameter overrides the corresponding parameter in the messaging service, if configured. The media_urls property expects a JSON array.

    • facebook_messenger

      Deprecated.

    • alexa

      Deprecated.

POST /v1/Services/{ServiceSid}/Notifications
curl \
 --request POST 'https://notify.twilio.com/v1/Services/{ServiceSid}/Notifications' \
 --user "username:password" \
 --header "Content-Type: application/x-www-form-urlencoded" \
 --data 'Body=body&Title=test&Identity=jing&Priority=high&DeliveryCallbackUrl=hello'
{"Body"=>"body", "Title"=>"test", "Identity"=>"jing", "Priority"=>"high", "DeliveryCallbackUrl"=>"hello"}
{"Body"=>"body", "ToBinding"=>"{\"binding_type\":\"apn\", \"address\":\"0efb85d06b3cc1bf290545fde4775a929d46b3541aaa4aa167e420b6c8b0ff15\"}"}
Response examples (201)
{
  "apn": null,
  "fcm": null,
  "gcm": null,
  "sid": "NTb8021351170b4e1286adaac3fdd6d082",
  "sms": null,
  "ttl": 2419200,
  "body": "body",
  "data": null,
  "tags": [],
  "alexa": null,
  "sound": null,
  "title": "test",
  "action": null,
  "priority": "high",
  "segments": [],
  "identities": [
    "jing"
  ],
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "IS699b53e02da45a1ba9d13b7d7d2766af",
  "date_created": "2016-03-24T23:42:28Z",
  "facebook_messenger": null
}
{
  "apn": null,
  "fcm": null,
  "gcm": null,
  "sid": "NTb8021351170b4e1286adaac3fdd6d082",
  "sms": null,
  "ttl": 2419200,
  "body": "body",
  "data": null,
  "tags": [],
  "alexa": null,
  "sound": null,
  "title": null,
  "action": null,
  "priority": "high",
  "segments": [],
  "identities": [],
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "IS699b53e02da45a1ba9d13b7d7d2766af",
  "date_created": "2016-03-24T23:42:28Z",
  "facebook_messenger": null
}