API Recipes

Phone Verification Flow

This recipe was an interactive walkthrough in the previous portal. Each step below names the API call it makes; open it in the API Reference to try it.

Overview

Secure Phone Verification Flow

Welcome to the Twilio Verify V2 API recipe! This guide demonstrates how to implement a secure phone number verification using OTP via SMS.

🚀 What's Inside?

This workflow covers the core lifecycle of a verification:

  1. Create a Service: Initialize a Verify Service to manage your verification configuration.
  2. Start Verification: Send a one-time passcode (OTP) to a user's phone number.
  3. Check Verification: Validate the code provided by the user to confirm ownership.

🛠 Prerequisites

  • Twilio Account SID and Auth Token must be configured.
  • A valid phone number capable of receiving SMS.

Ready to secure your user onboarding? detailed instructions follow in Step 1!

Step 1: Create Verify Service

Create a new Verify Service to manage verification settings.

API call: CreateService

Example arguments:

{
            FriendlyName: `APIMATIC ${new Date().toISOString().split('T')[0]}`
          }

Step 2: Start Verification

Trigger an OTP SMS to the target phone number.

API call: CreateVerification

Example arguments:

{
            ServiceSid: serviceSid,
            To: "+15017122661", // Replace with a valid phone number for testing
            Channel: "sms"
          }

Step 3: Check Verification Code

Validate the OTP code received on the phone.

API call: CreateVerificationCheck

Example arguments:

{
            ServiceSid: serviceSid,
            To: to,
            Code: "123456" // User should replace this with the actual code received
          }

On this page