diff --git a/src/Twilio/Clients/TwilioRestClient.cs b/src/Twilio/Clients/TwilioRestClient.cs
index b337a30f2..01d725a9b 100644
--- a/src/Twilio/Clients/TwilioRestClient.cs
+++ b/src/Twilio/Clients/TwilioRestClient.cs
@@ -28,7 +28,7 @@ public class TwilioRestClient : ITwilioRestClient
///
/// Account SID to use for requests
///
- public string AccountSid { get; }
+ public string AccountSid => _accountSid ?? throw new ArgumentException("AccountSID not set in " + nameof(TwilioClient) + "." + nameof(TwilioClient.Init));
///
/// Twilio region to make requests to
@@ -42,6 +42,7 @@ public class TwilioRestClient : ITwilioRestClient
private readonly string _username;
private readonly string _password;
+ private readonly string _accountSid;
///
/// Constructor for a TwilioRestClient
@@ -65,7 +66,16 @@ public TwilioRestClient(
_username = username;
_password = password;
- AccountSid = accountSid ?? username;
+ _accountSid = accountSid;
+ //Validate prefix in accountSid, https://www.twilio.com/docs/glossary/what-is-a-sid#common-sid-prefixes
+ if (_accountSid?.StartsWith("AC", StringComparison.Ordinal) == false)
+ throw new ArgumentException("AccountSid must start with \"AC\"", nameof(accountSid));
+ if (_accountSid == null)
+ {
+ if (username.StartsWith("AC", StringComparison.Ordinal))
+ _accountSid = username;
+ }
+
HttpClient = httpClient ?? DefaultClient();
Region = region;