Sending bulk messages in twillo notify API via CURL (php)
Twilio developer evangelist here.
The ToBinding
parameter is an array of binding objects. Notify implements support for that by decoding multiple ToBinding
parameters from the request.
The curl example from the Notify documentation looks like this:
curl -X POST https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications \ --data-urlencode 'ToBinding={"binding_type":"sms", "address":"+15555555555"}' \ --data-urlencode 'ToBinding={"binding_type":"facebook-messenger", "address":"123456789123"}' \ -d 'Body=Hello Bob' \ -u 'your_account_sid:your_auth_token'
As you can see, there are two ToBinding
parameters included in the data.
As far as I can tell, PHP doesn't support building the body like that. http_build_query
appears to be useful, but builds arrays of data using name[index]
form, which we don't want. You can strip the [index]
out though, with something like the following:
$query = array("ToBinding" => array( json_encode(array("binding_type"=>"sms", "address"=>"+19991112222")), json_encode(array("binding_type"=>"sms", "address"=>"+19993334444"))));$data = http_build_query($query);$data = preg_replace('/%5B[0-9]+%5D/simU', '', $data);echo $data;# => ToBinding=%7B%22binding_type%22%3A%22sms%22%2C%22address%22%3A%22%2B19991112222%22%7D&ToBinding=%7B%22binding_type%22%3A%22sms%22%2C%22address%22%3A%22%2B19993334444%22%7D
Let me know if this helps at all.