· Software Developer - Always Learning

Integration of Twilio for Phone Number Verification

Can anyone tell me how to do the integration since i wrote a custom action which is down below

import 'package:http/http.dart' as http;

Future<bool> sendVerificationCode(String phoneNumber) async {
  // Construct Twilio Verify API URL
  var url = Uri.parse('https://api.twilio.com/2010-04-01/Accounts/your_account_sid/Messages.json');
  
  // Add Twilio authentication credentials
  var auth = 'Basic ' + base64Encode(utf8.encode('your_account_sid:your_auth_token'));
  
  // Construct message body
  var body = json.encode({
    'To': phoneNumber,
    'From': 'your_twilio_phone_number',
    'Body': 'Your verification code is: 123456', // Generate your verification code dynamically
  });
  
  // Send HTTP POST request to Twilio API
  var response = await http.post(
    url,
    headers: <String, String>{
      'Content-Type': 'application/json',
      'Authorization': auth,
    },
    body: body,
  );

  // Check response status
  if (response.statusCode == 201) {
    // Verification code sent successfully
    return true;
  } else {
    // Error sending verification code
    return false;
  }
}

but getting 400 bad request where what to give for authentication