Q:

Twilio or Plivo SMS using Delphi

I am trying to figure out how to use Delphi 10 Seattle and Indy to send a POST request to either Plivo or Twilio for sending SMS messages.  When I use this code for Twilio efforts, I get an Unauthorized message in return (note that I have redacted my user name and Auth code):
procedure TSendTextForm. TwilioSendSms(FromNumber, ToNumber, Sms: string; Var Response: TStrings);

var
  apiurl, apiversion, accountsid, authtoken,
  url: string;
  aParams, aResponse: TStringStream;
  mHTTP : TidHttp;

begin

  mHTTP := TIdHTTP.Create(nil);

  apiurl := 'api.twilio.com';
  apiversion := '2010-04-01';
  accountsid := 'AC2f7cda1e6a4e74376***************:2b521b60208af4c*****************';
  url := Format('https://%s/%s/Accounts/%s/SMS/Messages/', [apiurl, apiversion, accountsid]);
  aParams := TStringStream. Create ;
try
  aParams. WriteString('&From=' + FromNumber);
  aParams. WriteString('&To=' + ToNumber);
  aParams. WriteString('&Body=' + Sms);
  aResponse := TStringStream. Create;
try
  mHTTP.Post(url, aParams, aResponse);
finally
  Response. Text  := aResponse. DataString;
end;
finally
  aParams. Free;
end;
end;

I have similar code for Plivo.  Neither company has any Delphi support.  Can anyone tell me what I'm missing above here?  Thanks so much. 
Mic

A:

Twilio evangelist here. 
In addition to the Basic Auth suggestion made by @mjn above, there are two other issues in your sample I believe will cause you problems:
First, in the code example above, your URL will be wrong because the accountsid variable is concatenating together both your sid and auth token.   
accountsid := 'AC2f7cda1e6a4e74376***************:2b521b60208af4c*****************';

While you do want to do this in order to use Basic Authentication, you don't want the auth token as part of the URL.   When you create the url property you just want to put the SID into the URL as the parameter like this: 
/Accounts/ACXXXXXXX/
Second, I would also suggest not using the /SMS resources as its deprecated.   Instead use /Messages which is newer and has more features:
/Accounts/ACXXXXXXX/Messages

