plivo / plivo-php

Plivo PHP Helper Library
http://www.plivo.com
MIT License
110 stars 117 forks source link

Client Error Response while sending SMS #20

Closed manthan787 closed 8 years ago

manthan787 commented 9 years ago

I get the following error while trying to make a POST request to send message:

Client error response [status code] 400 [reason phrase] BAD REQUEST [url] https://api.plivo.com/v1/Account/{AUTH ID}/Message/

When you look at the trace, there's an exception being thrown by Guzzle. But there's no way to know what may be wrong with the request being made by Plivo.

Any idea how to solve this?

cachrisman commented 8 years ago

@Manthan787 Are you still having this issue? We just released a new version of the library to support the newest version of guzzle. Hopefully that fixed this problem.

manthan787 commented 8 years ago

@cachrisman Yes it's working perfectly now!

dbelieves commented 8 years ago

Hi, i am not able to send an sms i get the following error:

HTTP/1.1 400 BAD REQUEST Content-Type: application/json Date: Wed, 02 Dec 2015 16:41:59 GMT Server: nginx/1.6.2 X-Plivo-Signature: 7VTk7wira5OfTDfbKbs7yxEyzbo= Content-Length: 103 Connection: keep-alive { "api_id": "9a7f2d78-9913-11e5-bd65-22000ae3016b", "error": "invalid json data sent in raw POST" }

I am using CURL.

cachrisman commented 8 years ago

@dbelieves are you using the latest version of the plivo-php helper library? please share the code you use to send sms.

dbelieves commented 8 years ago

@cachrisman, its resolved. had smart quotes in query.

Amarja commented 8 years ago

I update composer and install new plivo as well as guzzle but, now I am getting error as,

"Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: self signed certificate in certificate chain..."

Before updating composer.json it works very well. So how to solve this problem?

cachrisman commented 8 years ago

@Amarja can you post your composer.json and the code where you use a Plivo function which causes this error?

Amarja commented 8 years ago

@cachrisman thanks for your reply.

My composer.json looks like, { "require": { "php": ">=5.5.9", "laravel/framework": "5.1.*", "illuminate/html": "^5.0", "plivo/plivo-php": "~1.1.0" }, } In my plivo folder's composer.json, "require": { "guzzlehttp/guzzle": "v6.1.1" },

and my Plivo folder is in the root folder. I have used plivo functionality into simple php file.

<?php require 'vendor/autoload.php'; use Plivo\RestAPI;

$auth_id = "XXXXXXXXXXXXXXXXXXXX"; $auth_token = "XXXXXXXXXXMjIzODExMTg3NzZXXXXX";

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

// Set message parameters $params = array( 'src' => '141548XXXXX', 'dst' => '91XXXXXXXXXX', 'text' => 'Hi, I am Amarja :)', 'url' => 'http://localhost/untitled/sentsms.php', 'method' => 'POST' ); // Send message $response = $p->send_message($params);

echo "Response : "; print_r ($response['response']); echo"error code is:".curl_easy_strerror(); echo "
Api ID : {$response['response']['api_id']}
";

echo "Message UUID : {$response['response']['message_uuid'][0]}
";

?>

cachrisman commented 8 years ago

@Amarja you have to have a publicly available url set as the url parameter. That is telling Plivo to post the message details to that url but Plivo can't access your localhost. Try ngrok

Amarja commented 8 years ago

@cachrisman I tried after changing url, still having same issue....But before updating composer.json it works well and I'm getting this problems after updating the updating composer.json. Is there any other package that I am not updating?

cachrisman commented 8 years ago

@amarja can you make a fresh project (make a new directory and do a composer init and choose the plivo-php package and then do composer install) and copy in your php file and see if that works?

Amarja commented 8 years ago

@cachrisman Thanks so much for your reply, I will try this..

ariyawansha81 commented 8 years ago

i got the following error when use the latest plivo.php.

Parse error: syntax error, unexpected '[', expecting ')' in /home15/clientke/public_html/smst2/plivo.php on line 41

following is my test sending php file <?php require 'plivo.php';

$auth_id = "xxxxxx";
$auth_token = "xxxxx";

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

// Send a message
$params = array(
        'src' => 'Company name', // Sender's phone number with country code
        'dst' => '61490xxxx', // Receiver's phone number with country code
        'text' => 'Hi, Message from Plivo', // Your SMS text message
                    'url' => 'https://glacial-harbor-8656.herokuapp.com/report', // The URL to which with the status of the message is sent
        'method' => 'POST' // The method used to call the url
        //'text' => 'こんにちは、元気ですか?' # Your SMS Text Message - Japanese
        //'text' => 'Ce est texte généré aléatoirement' # Your SMS Text Message - French
    );
// 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>";

?>

Amarja commented 8 years ago

I want to send a sms using custom from variable. For that I made it as 'src' => 'custom name', then I checked at plivo's account site here in the sms logs it shows me 'custom name' as source, but when actual sms was sent to the mobile then it shows 'VM-PLVSMS' as a source/from on the mobile. I want to change it to the custome one. Any idea how can I change it? Thanks in advance.

Ramya-Raghu commented 8 years ago

@Amarja you will have to register the custom alpha-numeric sender id with the carrier. Please write to support@plivo.com with the details and we'll register it for you.

Amarja commented 8 years ago

@Ramya-Raghu thanks for your quick reply. I will go through it.

npatkar commented 8 years ago

Hi , While writing sample send sms php script I am facing following error. Please help me to fix this.

Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: self signed certificate in certificate chain (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\xampp\htdocs\public\mydomain_com\plivo\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187 Stack trace: #0 C:\xampp\htdocs\public\mydomain_com\plivo\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 C:\xampp\htdocs\public\mydomain_com\plivo\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 C:\xampp\htdocs\public\mydomain_com\plivo\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(G in C:\xampp\htdocs\public\mydomain_com\plivo\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

Below is my php script

`<?php require 'vendor\autoload.php'; use Plivo\RestAPI; $auth_id = "VALID_AUTH_ID"; $auth_token = "VALID_AUTH_TOKEN"; $p = new RestAPI($auth_id, $auth_token);

// Set message parameters
$params = array(
    'src' => '19999999999', // Sender's phone number with country code
    'dst' => '18888888888', // Receiver's phone number with country code
    'text' => 'Hi, Message from Plivo', // Your SMS text message
    'url' => 'http://www.mydomain.com/plivo/send_sms_status.php', // The URL to which with the status of the message is sent
    'method' => 'POST' // The method used to call the url
);
// Send message
$response = $p->send_message($params);

// Print the response
$mid = $response['response']['message_uuid'][0];
error_log("SEND_SMS :: Message UUID :  $mid \n", 3, "C:\sms_log.txt");

?>`

my composer.json is

{ "name": "plivo/plivo-php", "description": "Plivo PHP helper library to access PlivoCloud API and generate Plivo XML", "authors": [ { "name": "Plivo Team", "email": "hello@plivo.com" }, { "name": "Ben McInturff", "email": "benmcinturff@gmail.com" }, { "name": "Adam Homsi", "email": "adam.homsi@gmail.com" }, { "name": "Radu Topala", "email": "radu.topala@trisoft.ro" } ], "license": "MIT", "require": { "guzzlehttp/guzzle": "~6.0" }, "autoload": { "classmap": ["plivo.php"] } }

cachrisman commented 8 years ago

You should use composer init in your project directory to make a new composer.json file for your project which then references the plivo/plivo-php package. See https://getcomposer.org/doc/01-basic-usage.md and https://getcomposer.org/doc/03-cli.md#init for more details

Amarja commented 8 years ago

Generally when we get OTP from any site then usually it is in the specific format. I am using plivo but I don't know how to insert that OTP with specific format. Here is my code,

// Set message parameters $params = array( 'src' => '19999999999', // Sender's phone number with country code 'dst' => '18888888888', // Receiver's phone number with country code 'text' => 'OTP is '.$otp.'.' , // I want this OTP number in appropriate format 'url' => 'http://www.mydomain.com/ // The URL to which with the status of the message is sent 'method' => 'POST' // The method used to call the url );

Please give any suggestions, Thanks a lot in advance.

cachrisman commented 8 years ago

@amarja that code will work provided src is a valid Number in your account. Is that not working?

Amarja commented 8 years ago

@cachrisman Thanks, now it's working properly :)

Andre-Sekou commented 7 years ago

Hi everyone! I have the same issue like npatkar commented on 27 Mar 2016. I see that no suitable answer was given to the the problem. Please have a look at that. I am using CI and when i redirect to the view which has the sample script you guys put onto your website I have ssl error...