title: POST request from Salesforce Marketing Cloud cloudpage to Twilio using SSJS
body: <p>I am trying to send a POST request to Twilio's SMS API from Marketing Cloud's cloudpage using SSJS. I am getting a 401 unauthorized access even though I have added ACCOUNT_SID AND AUTH_TOKEN in the URL.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript" runat="server"&gt;
        Platform.Load("core", "1");
    
    var config = {
          endpoint: "https://XXXX:XXXX@api.twilio.com/2010-04-01/Accounts/XXXX/Messages.json",
          contentType: "application/x-www-form-urlencoded",
         payload : "From=+0000&amp;To=+0000&amp;Body=Test1"
      }
    try {
          var httpResult = HTTP.Post(config.endpoint, config.contentType, config.payload);
              var result = JSON.parse(httpResult.response);
      Write(httpResult.StatusCode);
           Write('result' + result);
    } catch(error) { Write(Stringify(error)); }
    &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I get this error:
  {&quot;message&quot;:&quot;An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.&quot;,&quot;description&quot;:&quot;ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --&gt; \r\n\r\n --- inner exception 1---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (401) Unauthorized. - from System\r\n\r\n\r\n\r\n&quot;}</p>
  <p>I have tried using client side JavaScript, but I get the same error.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script&gt;
  
  const url = 'https://XXXX:XXXX@api.twilio.com/2010-04-01/Accounts/XXXX/Messages.json';
    
    var xhr = new XMLHttpRequest();
  xhr.open("POST", url);
  
  xhr.setRequestHeader("Accept", "application/x-www-form-urlencoded");
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
   var data = 'From=+0000&amp;To=+0000&amp;Body=Test1';
  
  xhr.send(data);
   
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>