Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Obtain APNs credentials


(new)

Beta

The Push Notifications API is part of the Twilio Communications API, currently available as a Private Beta product. The information contained in this document is subject to change. You acknowledge and agree that your use of the Twilio Communications API is subject to the terms of the Services in Private Beta(link takes you to an external page). This
means that some features are not yet implemented and others may be changed before the product is declared as Generally Available. Private Beta products are not covered by the Twilio Support Terms or Twilio Service Level Agreement.

Request access to the private beta through the private beta access request form(link takes you to an external page).


Overview

overview page anchor

To send push notifications to Apple devices and Safari browsers, you need Apple Push Notification service (APN) credentials. This guide walks you through creating an App ID, generating a push notification certificate, and extracting the credentials required by the Twilio Communications API.


  • An Apple Developer account
  • Access to the Apple Developer Portal(link takes you to an external page)
  • macOS with Keychain Access
  • OpenSSL installed (included by default on macOS)

If you already have an App ID configured with push notifications, skip to Create a certificate.

  1. Navigate to the Apple Developer Portal(link takes you to an external page).
  2. Under Certificates, IDs & Profiles , select Identifiers .
    The Apple Developer Portal Program resources page with the Identifiers link highlighted under Certificates, IDs & Profiles.
  3. Click the + button next to Identifiers .
    Identifiers section with a blue plus button for adding new entries under Certificates, Identifiers & Profiles.
  4. Select App IDs and click Continue .
    Register a new identifier screen with options for App IDs, Services IDs, and Pass Type IDs, including descriptions.
  5. Complete the App ID registration form with your app details.

  1. In the Apple Developer Portal, select Certificates under Certificates, IDs & Profiles .
    App Store Connect resources and Certificates, IDs & Profiles management options for app development and testing.
  2. Click the + button next to Certificates .
    Certificates section with a blue plus icon for adding new certificates in the Certificates, Identifiers & Profiles interface.
  3. Select Apple Push Notification service SSL (Sandbox & Production) and click Continue .
    Services setup screen featuring options for Apple Push Notification SSL and Pass Type ID Certificate selection.
  4. Select your App ID from the dropdown menu.
  5. Create a Certificate Signing Request (CSR) by following Apple's CSR guide(link takes you to an external page).
  6. Upload your CSR file.
  7. Download the generated certificate.

  1. Double-click the downloaded certificate to install it in Keychain Access.
  2. Open Keychain Access and locate the certificate. It will be named Apple Push Services: [your app id].
  3. Right-click the certificate and select Export.
  4. Save the file as a .p12 file. This file contains both the certificate and private key.

The certificate and private key must be extracted from the .p12 file and base64 encoded before uploading to Twilio.

Extract and encode the certificate

extract-and-encode-the-certificate page anchor

Open a terminal in the directory where the .p12 file is saved and run the following command.

openssl pkcs12 -in cred.p12 -nokeys -nodes -legacy | openssl x509 | base64 -b 0
(information)

Info

Replace cred.p12 with the actual filename of your exported certificate.

Extract and encode the private key

extract-and-encode-the-private-key page anchor
openssl pkcs12 -in cred.p12 -nocerts -nodes -legacy | openssl rsa | base64 -b 0
(information)

Info

Replace cred.p12 with the actual filename of your exported certificate.


Upload credentials to Twilio

upload-credentials-to-twilio page anchor

Use the base64-encoded strings as the certificate and privateKey values when creating your APNs credential.

1
curl -X POST 'https://comms.twilio.com/preview/PushNotifications/Credentials' \
2
-H 'Content-Type: application/json' \
3
-d '{
4
"credentialType": "APN",
5
"content": {
6
"certificate": "YOUR_BASE64_ENCODED_CERTIFICATE",
7
"privateKey": "YOUR_BASE64_ENCODED_KEY"
8
},
9
"appName": "YOUR_APP_NAME"
10
}' \
11
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN