# Notifications Resource

## Description

This resource is meant to be used when implementing Verify Push. It lets developers request that Verify Push retry sending a push notification for the same Challenge. Previously, there was a 1:1 mapping between a Challenge and push notification, so developers had to create a new, duplicate Challenge to resend a push notification for the same verification action (e.g. two-factor auth for a user login). They then had to deduplicate the Challenges on the client side. This implementation complexity is removed with this resource.

> \[!WARNING]
>
> The Notifications resource is currently in the Pilot maturity stage, please
> check with Twilio before using it in production.

> \[!NOTE]
>
> **APNs/FCM behavior**: Please be aware that APNs and FCM already have built-in queuing and retry logic for the scenario where the device was offline when the push notification was requested. When the device becomes online again, all non-expired push notifications (based on the push's time-to-live / ttl) will be sent again. We recommend that developers limit the number of retries a user can request, so that the user doesn't accidentally "over-request" and end up getting a flood of push notifications. We have also made `ttl` a configurable resource parameter, so developers can expire past push notifications more quickly if this becomes a problem.
>
> **Challenge expiration**: The Challenge itself can still expire. Requesting a retry push notification on an expired Challenge will result in an error response, and developers will need to create a new Challenge. This won't create a deduplication problem for the client-side though, because the client can just request pending, not expired, Challenges.

## Notification Properties

```json
{"type":"object","refName":"verify.v2.service.entity.challenge.notification","modelName":"verify_v2_service_entity_challenge_notification","properties":{"sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NT[0-9a-fA-F]{32}$","nullable":true,"description":"A 34 character string that uniquely identifies this Notification."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Account."},"service_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^VA[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Service."},"entity_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^YE[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Entity."},"identity":{"type":"string","nullable":true,"description":"Customer unique identity for the Entity owner of the Challenge. This identifier should be immutable, not PII, length between 8 and 64 characters, and generated by your external system, such as your user's UUID, GUID, or SID. It can only contain dash (-) separated alphanumeric characters.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"challenge_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^YC[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Challenge."},"priority":{"type":"string","nullable":true,"description":"The priority of the notification. For `push` Challenges it's always `high` which sends the notification immediately, and can wake up a sleeping device."},"ttl":{"type":"integer","default":0,"description":"How long, in seconds, the notification is valid. Max: 5 minutes"},"date_created":{"type":"string","format":"date-time","nullable":true,"description":"The date that this Notification was created, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."}}}
```

## Resend Push Notification

`POST https://verify.twilio.com/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges/{ChallengeSid}/Notifications`

> \[!WARNING]
>
> Only 3 Push Notifications can be created per Challenge

### Path parameters

```json
[{"name":"ServiceSid","in":"path","description":"The unique SID identifier of the Service.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^VA[0-9a-fA-F]{32}$"},"required":true},{"name":"Identity","in":"path","description":"Customer unique identity for the Entity owner of the Challenge. This identifier should be immutable, not PII, length between 8 and 64 characters, and generated by your external system, such as your user's UUID, GUID, or SID. It can only contain dash (-) separated alphanumeric characters.","schema":{"type":"string"},"x-twilio":{"pii":{"handling":"standard","deleteSla":30}},"required":true},{"name":"ChallengeSid","in":"path","description":"The unique SID identifier of the Challenge.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^YC[0-9a-fA-F]{32}$"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"CreateNotificationRequest","properties":{"Ttl":{"type":"integer","description":"How long, in seconds, the notification is valid. Can be an integer between 0 and 300. Default is 300. Delivery is attempted until the TTL elapses, even if the device is offline. 0 means that the notification delivery is attempted immediately, only once, and is not stored for future delivery."}}},"examples":{"createWithTtl":{"value":{"lang":"json","value":"{\n  \"Ttl\": 150\n}","meta":"","code":"{\n  \"Ttl\": 150\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"Ttl\"","#7EE787"],[":","#C9D1D9"]," ",["150","#79C0FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}},"createWithoutTtl":{"value":{"lang":"json","value":"{}","meta":"","code":"{}","tokens":[["{}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Create a Notification

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function createNotification() {
  const notification = await client.verify.v2
    .services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .entities("Identity")
    .challenges("YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .notifications.create();

  console.log(notification.sid);
}

createNotification();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

notification = (
    client.verify.v2.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .entities("Identity")
    .challenges("YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .notifications.create()
)

print(notification.sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Verify.V2.Service.Entity.Challenge;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var notification = await NotificationResource.CreateAsync(
            pathServiceSid: "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathIdentity: "Identity",
            pathChallengeSid: "YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(notification.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.verify.v2.service.entity.challenge.Notification;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Notification notification =
            Notification.creator("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Identity", "YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .create();

        System.out.println(notification.getSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	verify "github.com/twilio/twilio-go/rest/verify/v2"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &verify.CreateNotificationParams{}

	resp, err := client.VerifyV2.CreateNotification("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"Identity",
		"YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Sid != nil {
			fmt.Println(*resp.Sid)
		} else {
			fmt.Println(resp.Sid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$notification = $twilio->verify->v2
    ->services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->entities("Identity")
    ->challenges("YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->notifications->create();

print $notification->sid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

notification = @client
               .verify
               .v2
               .services('VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
               .entities('Identity')
               .challenges('YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
               .notifications
               .create

puts notification.sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:verify:v2:services:entities:challenges:notifications:create \
   --service-sid VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --identity Identity \
   --challenge-sid YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X POST "https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/Identity/Challenges/YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "sid": "NTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "entity_sid": "YEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "identity": "Identity",
  "challenge_sid": "YCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "2015-07-30T20:00:00Z",
  "priority": "high",
  "ttl": 150
}
```
