-1

I want to send bulk messages using twillio notify API using CURL in php I'm trying below Code :

$data = [];
    $data['ToBinding'] =  array("binding_type"=>"sms", "address"=>"+12013318779");
    $data['Body'] ="test";
    $ch = curl_init("https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXX/Notifications");
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    
    curl_setopt($ch, CURLOPT_USERPWD,'XXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXX');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $resultData = curl_exec($ch);

I think I'm doing something wrong with the CURLOPT_POSTFIELDS but I tried each and every thing to change that but every time I got the below response :

{"code": 20001,
"message": "At least one parameter among Identity, Tag, and ToBinding must be specified",
"more_info": "https://www.twilio.com/docs/errors/20001",
"status": 400}

Can you guys please help me out.

Thanks

1 Answers1

-1

Twilio developer evangelist here.

ToBinding requires the data to be encoded as JSON. Try the following:

$data['ToBinding'] =  json_encode(array("binding_type"=>"sms", "address"=>"+12013318779"));

Hope that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88