twilio-php: Unable to create record: authenticate

I’m getting the following error message: Uncaught exception ‘Twilio\Exceptions\RestException’ with message ‘[HTTP 401] Unable to create record: Authenticate’

Below is my script.

<?php
error_reporting(E_ALL);
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require  'autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'SK679251dde54ae13ed6cabeeb1e5ffcf2';
$token = 'token';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+15555555555',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+15555555555',
        // the body of the text message you'd like to send
        'body' => "Hey Jenny! Good luck on the bar exam!"
    )
);

?>

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (4 by maintainers)

Most upvoted comments

Based off the snippet you provided, it looks like you are trying to use an API Key (SK Sid Prefix is used for an API Key).

When using an API Key you should construct the client, as follows.

<?php

require 'autoload.php';

use Twilio\Rest\Client;

$keySid = 'SK679251dde54ae13ed6cabeeb1e5ffcf2';
$keySecret = 'the-secret-returned-on-creation';
$accountSid = 'ACyouraccountsid';

$client = new Client($keySid, $keySecret, $accountSid);

// Use the $client to do things

out issue was not sufficient funds :\ drove us nutts lol.

What is $keysecret and $accountsid in this file? I have token and sid only

Hello @naveen509 the issue was that there was no money in the account.