Getting started overview

Getting started with Telnyx involves a sequence of steps designed to enable developers to integrate programmable communication features into their applications. The process generally begins with account creation, followed by the generation of API keys, and concludes with executing an initial API request to confirm connectivity and functionality. Telnyx provides a developer portal with comprehensive documentation, API references, and code examples for various programming languages to assist with this integration process Telnyx developer documentation.

The core objective of the getting started process is to establish a foundational understanding of how to interact with the Telnyx API, manage communication resources like phone numbers, and implement basic functionalities such as sending SMS messages or making programmable voice calls. Developers can choose to use one of the officially supported SDKs or interact directly with the REST API using tools like cURL or HTTP client libraries in their chosen language.

This guide outlines the essential steps from initial signup to making a successful API call. A quick-reference table summarizes the key actions:

Step What to do Where
1. Sign up Create a Telnyx account. Telnyx homepage
2. Verify Complete email and possibly phone verification. Telnyx Portal
3. API Keys Generate an API key for authentication. Telnyx Portal > API Keys
4. Install SDK (Optional) Install a Telnyx SDK for your chosen language. Package manager (e.g., pip, npm)
5. First Request Make a simple API call (e.g., send an SMS). Your code editor/terminal
6. Configure Numbers Purchase or port a phone number and assign a profile. Telnyx Portal > Numbers

Create an account and get keys

To begin, navigate to the Telnyx website and initiate the account creation process. This typically involves providing an email address, setting a password, and agreeing to the terms of service. Following initial signup, you will need to verify your email address. Additional verification steps, such as phone number confirmation, may be required to fully enable account features and access the initial $20 credit Telnyx pricing details.

Once your account is active, log in to the Telnyx Portal. The API Key generation interface is usually located under the 'API Keys' section within the account settings or developer dashboard. Create a new API key, which will serve as your primary authentication credential for programmatic access to the Telnyx API. This key should be treated as sensitive information and stored securely, typically as an environment variable or using a secret management solution, rather than hardcoding it directly into your application's source code.

Telnyx API keys function as bearer tokens for authentication. When making API requests, this key is included in the Authorization header of your HTTP request, prefixed with Bearer. For example: Authorization: Bearer YOUR_API_KEY. This method aligns with common practices for securing RESTful APIs, as detailed in specifications like OAuth 2.0 Bearer Token Usage OAuth 2.0 Bearer Token Usage specification.

Your first request

After obtaining an API key, the next step is to make a simple API call to verify your setup. A common first request involves sending an SMS message. This requires a Telnyx phone number capable of sending SMS, which you can purchase or configure within the Telnyx Portal under the 'Numbers' section Telnyx Messaging Profiles guide.

Choose your preferred programming language. Telnyx provides official SDKs for Python, Node.js, Ruby, PHP, Java, Go, and C#. Alternatively, you can use cURL for direct HTTP requests.

Using cURL (HTTP Request)

To send an SMS using cURL, replace YOUR_API_KEY, +15017122661 (your Telnyx number), and +15551234567 (recipient number) with your actual values:

curl -X POST "https://api.telnyx.com/v2/messages" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
        "from": "+15017122661",
        "to": "+15551234567",
        "text": "Hello from Telnyx!"
      }'

Using Python SDK

First, install the Python SDK:

pip install telnyx

Then, use the following Python code snippet:

import telnyx
import os

telnyx.api_key = os.environ.get("TELNYX_API_KEY")

try:
    message = telnyx.Message.create(
        from_="+15017122661", # Your Telnyx messaging-enabled number
        to="+15551234567",   # Recipient number
        text="Hello from Telnyx using Python SDK!"
    )
    print("Message sent successfully!")
    print(message)
except telnyx.TelnyxError as e:
    print(f"Error sending message: {e}")

Remember to set your Telnyx API key as an environment variable named TELNYX_API_KEY. Replace the from_ and to numbers with your purchased Telnyx number and the recipient's number, respectively.

Using Node.js SDK

First, install the Node.js SDK:

npm install telnyx

Then, use the following Node.js code snippet:

const telnyx = require('telnyx')(process.env.TELNYX_API_KEY);

async function sendMessage() {
  try {
    const message = await telnyx.messages.create({
      from: '+15017122661', // Your Telnyx messaging-enabled number
      to: '+15551234567',   // Recipient number
      text: 'Hello from Telnyx using Node.js SDK!',
    });
    console.log('Message sent successfully!');
    console.log(message);
  } catch (error) {
    console.error('Error sending message:', error);
  }
}

sendMessage();

Ensure that your Telnyx API key is available as an environment variable named TELNYX_API_KEY. Update the from and to numbers.

Upon successful execution, the API will return a 200 OK status code and a message object containing details of the sent SMS. If an error occurs, the response will include an error code and a descriptive message Telnyx Messages API reference.

Common next steps

Once you have successfully sent your first message or made a call, consider these next steps to further integrate Telnyx into your application:

  • Explore other APIs: Telnyx offers APIs for voice, SIP trunking, number management, and WebRTC. Review the Telnyx API reference documentation to understand other capabilities.
  • Configure Webhooks: Set up webhooks to receive real-time notifications about events such as inbound messages, call status changes, or delivery receipts. This allows your application to react dynamically to communication events. Consult the Telnyx Webhooks documentation for setup instructions.
  • Manage Numbers: Purchase additional phone numbers, configure their capabilities (voice, SMS, MMS), and assign them to messaging or call control profiles within the Telnyx Portal.
  • Implement Error Handling: Build robust error handling into your application to manage potential API request failures, rate limit issues, or invalid parameters.
  • Utilize SDKs: If you started with cURL, consider integrating one of the Telnyx SDKs for your preferred language to simplify API interactions and reduce boilerplate code.
  • Monitor Usage: Track your API usage and spending within the Telnyx Portal to manage costs and ensure efficient resource utilization.

Troubleshooting the first call

If your first API call does not succeed, consider the following common issues and troubleshooting steps:

  • API Key Issues:
    • Invalid Key: Double-check that your API key is correct and hasn't been truncated or altered. Ensure it's passed with the Bearer prefix in the Authorization header.
    • Expired Key: While Telnyx API keys generally don't expire, confirm its status in the Telnyx Portal.
    • Permissions: Verify that the API key has the necessary permissions for the requested operation (e.g., sending messages).
  • Number Configuration:
    • Messaging Profile: For sending SMS, ensure your Telnyx number is assigned to a messaging profile and that the profile is correctly configured for outbound messaging. Refer to the Telnyx Messaging Profiles guide.
    • Number Capabilities: Confirm that the Telnyx number you are using has SMS capabilities enabled.
    • Recipient Number: Ensure the recipient number is correctly formatted (E.164 format, e.g., +15551234567) and valid.
  • Account Balance:
    • Insufficient Funds: Telnyx operates on a pay-as-you-go model. Ensure your account has sufficient credit to cover the cost of the operation. You can check your balance in the Telnyx Portal.
  • Network and Firewall:
    • Connectivity: Verify that your development environment has outbound internet connectivity to api.telnyx.com.
    • Firewall Rules: If you are behind a corporate firewall, ensure that connections to Telnyx API endpoints are permitted.
  • API Response and Error Messages:
    • Review Errors: Carefully examine the error messages returned by the API. Telnyx's API errors are typically descriptive and indicate the specific problem. For example, a 401 Unauthorized suggests an API key issue, while a 422 Unprocessable Entity often points to invalid request parameters Telnyx Error Handling documentation.
    • Logging: Implement comprehensive logging for API requests and responses in your application to help diagnose issues.
  • SDK Specific Issues:
    • Environment Variables: Confirm that your API key environment variable is correctly set and accessible by your application.
    • SDK Version: Ensure you are using a recent version of the Telnyx SDK.

If you continue to experience issues, refer to the official Telnyx documentation or contact Telnyx support for further assistance.