Getting started overview

Integrating GetOTP involves a sequence of steps designed to enable two-factor authentication (2FA) and phone verification capabilities within a software application. The process typically begins with account creation, followed by the acquisition of API credentials, and then proceeds to making a programmatic request using either the REST API or an official SDK. GetOTP provides a developer documentation portal that details these steps and offers language-specific examples.

The core objective of the getting started process is to successfully generate and verify a one-time password (OTP), demonstrating the fundamental functionality of the service. This typically involves sending an OTP to a user's phone number or email and then verifying the code submitted by the user. GetOTP supports various programming languages through its SDKs, including Python and Node.js, to streamline integration efforts.

Here is a quick reference table outlining the initial steps:

Step What to do Where to find it
1. Create Account Sign up for a new GetOTP account. GetOTP homepage
2. Get API Keys Locate and copy your API Key and API Secret. GetOTP Dashboard (after login)
3. Install SDK (Optional) Install the relevant SDK for your programming language. GetOTP documentation
4. Make First Request Send a 'generate OTP' request to a test number. GetOTP API reference or SDK examples
5. Verify OTP Send a 'verify OTP' request with the generated code. GetOTP API reference or SDK examples

Create an account and get keys

To begin using GetOTP, developers must first establish an account. This process initiates from the GetOTP homepage, where a signup option is available. GetOTP offers a Developer Plan which includes 500 free authentications per month, allowing initial exploration and testing without immediate cost. During the signup process, users typically provide an email address and create a password.

Upon successful account creation and login, users are directed to the GetOTP dashboard. Within this dashboard, an essential step is to locate and secure the API credentials. GetOTP typically provides an API Key and an API Secret. These keys are fundamental for authenticating all subsequent API requests. The API Key identifies the account, while the API Secret is used to sign requests, ensuring their authenticity and integrity.

The API Key is a unique identifier visible in the dashboard, often presented as a string of alphanumeric characters. The API Secret, crucial for cryptographic signing or direct authentication, is usually accessible from a dedicated 'API Keys' or 'Settings' section within the dashboard. It is recommended to treat the API Secret with the same security precautions as a password, avoiding hardcoding it directly into client-side code, and instead using environment variables or a secure configuration management system. Best practices for securing API keys are outlined by organizations such as Google Cloud's API key security guide.

Once obtained, these keys will be used in the authorization header of direct REST API calls or configured within the respective GetOTP SDKs. It is important to note that if keys are compromised, new ones can usually be generated from the dashboard, invalidating the old ones.

Your first request

After acquiring API credentials, the next step involves making a programmatic request to GetOTP. This demonstrates successful communication with the API and validates the setup. The typical first request involves generating a one-time password (OTP) and sending it to a specified recipient (e.g., a phone number).

GetOTP provides SDKs for several programming languages, including Python, Node.js, Ruby, PHP, and Java, which simplify the process of interacting with their API. Developers can choose to use an SDK or make direct HTTP requests to the REST API endpoints. The GetOTP API reference provides detailed information on available endpoints and required parameters.

Below are examples demonstrating how to generate an OTP using the Python and Node.js SDKs, which are among the primary language examples highlighted by GetOTP.

Python SDK Example: Generate OTP

First, install the Python SDK:

pip install getotp

Then, use the following Python code to generate and send an OTP:


from getotp import GetOTP

# Replace with your actual API Key and API Secret
api_key = "YOUR_GETOTP_API_KEY"
api_secret = "YOUR_GETOTP_API_SECRET"

otp_client = GetOTP(api_key, api_secret)

phone_number = "+15551234567" # Use a verified test number

try:
    response = otp_client.send_otp(phone_number=phone_number)
    if response['success']:
        print(f"OTP sent successfully to {phone_number}. OTP ID: {response['otp_id']}")
    else:
        print(f"Failed to send OTP: {response['message']}")
except Exception as e:
    print(f"An error occurred: {e}")

Node.js SDK Example: Generate OTP

First, install the Node.js SDK:

npm install getotp

Then, use the following Node.js code to generate and send an OTP:


const GetOTP = require('getotp');

// Replace with your actual API Key and API Secret
const apiKey = 'YOUR_GETOTP_API_KEY';
const apiSecret = 'YOUR_GETOTP_API_SECRET';

const otpClient = new GetOTP(apiKey, apiSecret);

const phoneNumber = '+15551234567'; // Use a verified test number

otpClient.sendOtp(phoneNumber)
  .then(response => {
    if (response.success) {
      console.log(`OTP sent successfully to ${phoneNumber}. OTP ID: ${response.otp_id}`);
    } else {
      console.error(`Failed to send OTP: ${response.message}`);
    }
  })
  .catch(error => {
    console.error(`An error occurred: ${error.message}`);
  });

After sending the OTP, the next logical step in a real-world scenario is to verify the code the user provides. This involves a separate API call, typically verify_otp, sending the OTP ID (received from the send request) and the user-entered code.

Common next steps

Once a successful OTP generation and verification flow has been established, developers typically proceed with several common next steps to fully integrate GetOTP into their applications:

  • Implement OTP Verification: Extend the initial 'generate OTP' request with the corresponding 'verify OTP' endpoint to complete the 2FA flow. This requires capturing the OTP entered by the user and sending it back to GetOTP for validation.
  • Error Handling and Retries: Integrate robust error handling mechanisms to manage failed OTP sends, invalid codes, or API rate limit issues. Implement retry logic where appropriate, particularly for transient network errors. The GetOTP documentation provides guidance on error codes.
  • Customization: Explore options for customizing OTP messages, sender IDs, or other parameters supported by GetOTP to align with application branding and user experience requirements.
  • User Management Integration: Link GetOTP's authentication status with your existing user management system. This involves updating user profiles to reflect successful 2FA setup or verification status.
  • Security Enhancements: Review and implement security best practices, such as storing API keys securely (e.g., using environment variables or a secrets manager), ensuring all communications are over HTTPS, and validating payloads.
  • Explore Advanced Features: Investigate additional GetOTP features like rate limiting, multi-channel OTPs (e.g., email fallback), or different OTP types if supported, to enhance security and user experience.
  • Monitoring and Logging: Set up monitoring and logging for OTP-related operations to track usage, identify potential issues, and audit authentication attempts.
  • Review Pricing and Scaling: Understand the GetOTP pricing model as usage scales beyond the free tier, and plan for potential upgrades to ensure service continuity. Paid plans start at $29/month for 5,000 authentications.

Troubleshooting the first call

Encountering issues during the initial API call is common. Here are troubleshooting steps for the 'generate OTP' request:

  • Check API Key and Secret: Double-check that the API Key and API Secret are copied correctly from your GetOTP dashboard. Ensure there are no leading or trailing spaces. Mismatched or incorrect credentials are a frequent cause of authentication failures, often resulting in 401 Unauthorized errors.
  • Verify Network Connectivity: Confirm that your development environment has outbound internet access and is not blocked by a firewall or proxy from reaching GetOTP's API endpoints.
  • Inspect Request Parameters: Ensure all required parameters, such as phone_number, are present in your request and formatted correctly. Refer to the GetOTP API reference for exact parameter names and expected data types.
  • Review SDK Configuration: If using an SDK, ensure it is initialized with the correct API credentials and that the method calls match the SDK's documentation. Incorrect SDK versions or dependencies can sometimes cause unexpected behavior.
  • Examine API Response and Error Messages: Pay close attention to the error messages returned by the GetOTP API. These messages are designed to be specific and can often pinpoint the exact problem, such as an invalid phone number format, an unsupported country code, or an account-specific limitation.
  • Check Account Status: Log into your GetOTP dashboard to ensure your account is active and not suspended or limited due to billing issues or policy violations. Check your remaining free tier authentications if on the Developer Plan.
  • Consult Documentation and Support: If issues persist, consult the comprehensive GetOTP documentation and FAQ sections. If the problem remains unresolved, contacting GetOTP support is the next step.
  • Test with cURL (for REST API): If you are making direct HTTP requests, try replicating the call using cURL to isolate whether the issue is with your code or the API interaction itself. This helps rule out SDK-specific problems.