0

I keep getting this error: "757: unexpected token at 'Could not verify your access level for that URL. You have to login with proper credentials" In my Ruby on Rails application.

Here's the code:

  def send_message_plivo
    p = RestAPI.new(ENV["PLIVO_AUTHID"], ENV["PLIVO_AUTHTOKEN"])

    params = {
      "src" => "1111111111",
      "dest" => "xxxxxxxxxxxxx", # <- my only verified number
      "text" => "Hi! From Plivo",
      "url" => "http://localhost:3000/sent_message_status",
      "method" => "POST"
    }

    response = p.send_message(params) # <- line of the error!
    puts response

  end

Do you know what am I missing?

ste
  • 3,087
  • 5
  • 38
  • 73
  • is the parameter really suppose to be "dest"? I see "dst" here: https://www.plivo.com/docs/api/message/ – Justin Steele Mar 14 '16 at 20:37
  • For PLIVO_AUTHID, are you using your plivo username or AUTH ID (20ish "random" character string)? – Justin Steele Mar 14 '16 at 20:39
  • You were both right. I had som problem with the env variables, I put directly the keys and changed "dest" to "dst" and it worked! – ste Mar 15 '16 at 07:28

2 Answers2

0

According to plivo.com/docs/api/message the parameter is suppose to be "dst" not "dest".

Also, double check the values your are using for your Plivo Auth ID and Auth Token. Make sure you are using your AUTH ID (20ish "random" character string) and not your Plivo username.

Justin Steele
  • 2,230
  • 13
  • 16
0

You have to do something like this :-

        $auth_id = 'PLIVO_AUTHID';
    $auth_token = 'PLIVO_AUTHTOKEN';

    $p = new RestAPI($auth_id, $auth_token);

    // Set message parameters
    $params = array(
            'src' => '1111111111', // Sender's phone number with country code
            'dst' => '2222222222', // Receiver's phone number with country code
            'text' => 'Hi, Message from Plivo', // Your SMS text message

            //'url' => 'http://example.com/report/', // The URL to which with the status of the message is sent
            'method' => 'GET' // The method used to call the url
    );
    // Send message
    $response = $p->send_message($params);

    // Print the response
    echo "Response : ";
    print_r ($response['response']);

    // Print the Api ID
    echo "<br> Api ID : {$response['response']['api_id']} <br>";

    // Print the Message UUID
    echo "Message UUID : {$response['response']['message_uuid'][0]} <br>";

And if you get response like this :-

Response : Array ( [api_id] => 2c5af359-1c06-11e6-8a00-22000ae28743 [message] => message(s) queued [message_uuid] => Array ( [0] => 0f2afda3-b869-45f6-9baf-13acc1992cb8 ) ) Api ID : 2c5af359-1c06-11e6-8a00-22000ae28743 Message UUID : 0f2afda3-b869-45f6-9baf-13acc1992cb8 

It means your message is sent.

Manish Silawat
  • 900
  • 5
  • 7
  • Unable to get or display received sms using plivo token and auth id in php?? https://stackoverflow.com/questions/67001536/unable-to-get-or-display-received-sms-using-plivo-token-and-auth-id-in-php –  Apr 08 '21 at 10:14
  • I think you are using wrong auth id and token. Try with correct one. Hope it will help you. – Manish Silawat Apr 08 '21 at 13:00
  • i have used correct auth id and token but it is showing ** Text Not Available ** in plivo ? –  Apr 08 '21 at 13:41