Skip to content

Instantly share code, notes, and snippets.

@wiserfirst
Last active July 20, 2022 07:17
Show Gist options
  • Save wiserfirst/a537b41cc05e61447ad38182db46bf49 to your computer and use it in GitHub Desktop.
Save wiserfirst/a537b41cc05e61447ad38182db46bf49 to your computer and use it in GitHub Desktop.
Create a mobile_push_credential and associate it with a SIP connection via API

Create new mobile_push_credential

Once you've obtained the certificate and private key for iOS (you can follow this guide for that), you can create a new iOS push_credential with the following request:

curl -X "POST" "https://api.telnyx.com/v2/mobile_push_credentials" \
     -H 'Authorization: Bearer <my-telnyx-api-key>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "certificate": "<my-iOS-Certificate>",
  "alias": "<my-alias-for-ios-credential>",
  "private_key": "<my-iOS-Private-Key>",
  "type": "ios"
}'

Similarly for Android, you can follow this guide to obtain a server key and then you can create a new Android push_credential with the following request:

curl -X "POST" "https://api.telnyx.com/v2/mobile_push_credentials" \
     -H 'Authorization: Bearer <my-telnyx-api-key>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "alias": "<my-alias-for-android-credential>",
  "type": "android",
  "server_key": "<my-Server-Key>"
}'

List existing mobile_push_credentials

If you already have some mobile_push_credentials create with Telnyx, you can get information about them with the following requests:

curl "https://api.telnyx.com/v2/mobile_push_credentials" \
     -H 'Authorization: Bearer <my-telnyx-api-key>'

Note: we'll need the id field for a mobile_push_credential, in order to assoicate it with a SIP connection.

Create new SIP connections

If you need new SIP connections, please follow our Portal Setup guide to create them.

Associate a mobile_push_credential to a SIP connection

Now that we are ready to associate a mobile_push_credentials to a SIP connections.

For an iOS push_credential, you can use the following request:

curl -X "PATCH" "https://api.telnyx.com/v2/credential_connections/<connection_id>" \
     -H 'Authorization: Bearer <my-telnyx-api-key>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "ios_push_credential_id": "<ios_push_credential_id>"
}'

And for Android push_credential:

curl -X "PATCH" "https://api.telnyx.com/v2/credential_connections/<connection_id>" \
     -H 'Authorization: Bearer <my-telnyx-api-key>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "android_push_credential_id": "<android_push_credential_id>"
}'

Note: to get the connection_id, you can visit the SIP Connections page on Portal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment