# Obtain APNs credentials

> \[!IMPORTANT]
>
> 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](https://www.twilio.com/en-us/legal/service-country-specific-terms/private-beta). 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](https://airtable.com/appqQFoQmQ9WDS1YW/pagDQFkMvNi7O28dN/form).

## Overview

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.

## Prerequisites

* An Apple Developer account
* Access to the [Apple Developer Portal](https://developer.apple.com/account)
* macOS with Keychain Access
* OpenSSL installed (included by default on macOS)

## Register an App ID

If you already have an App ID configured with push notifications, skip to [Create a certificate](#create-a-certificate).

1. Navigate to the [Apple Developer Portal](https://developer.apple.com/account).
2. Under **Certificates, IDs & Profiles**, select **Identifiers**.
   ![The Apple Developer Portal Program resources page with the Identifiers link highlighted under Certificates, IDs & Profiles.](https://docs-resources.prod.twilio.com/c13664503959c07ddba996303abae25a8e905cb9d904f7d93a5f58cbeed78312.png)
3. Click the **+** button next to **Identifiers**.
   ![Identifiers section with a blue plus button for adding new entries under Certificates, Identifiers & Profiles.](https://docs-resources.prod.twilio.com/144905f437d95f4f40a213bea51de0007450d98ec02474deffe1291eab6c0610.png)
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.](https://docs-resources.prod.twilio.com/96ff4834be9298ea94fc45f506c2a7ca589051f6f3f4dbdbf9ca3f9864cfaa54.png)
5. Complete the App ID registration form with your app details.

## Create a certificate

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.](https://docs-resources.prod.twilio.com/1b76b3fc5e5bdcabaf2150fd41af182c05bf3b3b66a60c16e85932f587de2b11.png)
2. Click the **+** button next to **Certificates**.
   ![Certificates section with a blue plus icon for adding new certificates in the Certificates, Identifiers & Profiles interface.](https://docs-resources.prod.twilio.com/ee8623f5c79641de1f68bb4c196fde4fec87a2a3cadddde205b1437aff6db09a.png)
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.](https://docs-resources.prod.twilio.com/5577e84cf169af537735b1f70f865f8e3d230a989c02b08f75df132be503e2f0.png)
4. Select your App ID from the dropdown menu.
5. Create a Certificate Signing Request (CSR) by following [Apple's CSR guide](https://developer.apple.com/help/account/certificates/create-a-certificate-signing-request).
6. Upload your CSR file.
7. Download the generated certificate.

## Export the 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.

## Encode the credentials

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

### Extract and encode the certificate

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

```bash
openssl pkcs12 -in cred.p12 -nokeys -nodes -legacy | openssl x509 | base64 -b 0
```

> \[!NOTE]
>
> Replace `cred.p12` with the actual filename of your exported certificate.

### Extract and encode the private key

```bash
openssl pkcs12 -in cred.p12 -nocerts -nodes -legacy | openssl rsa | base64 -b 0
```

> \[!NOTE]
>
> Replace `cred.p12` with the actual filename of your exported certificate.

## Upload credentials to Twilio

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

```bash
curl -X POST 'https://comms.twilio.com/preview/PushNotifications/Credentials' \
     -H 'Content-Type: application/json' \
     -d '{
          "credentialType": "APN",
          "content": {
            "certificate": "YOUR_BASE64_ENCODED_CERTIFICATE",
            "privateKey": "YOUR_BASE64_ENCODED_KEY"
          },
          "appName": "YOUR_APP_NAME"
        }' \
     -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

## Next steps

* Learn how to [send a push notification](/docs/comms/send-a-push#send-a-notification).
* Set up [FCM credentials](/docs/comms/fcm-credentials) to send notifications to Android devices.
