Closed gabrielaltea closed 1 year ago
The problem is in PHP, the Curl options are not like in Node, the perfect solution is to find the options that work, since having the server in Node, any PHP application can access this api using Curl, just like in other apis , for example Twilio.
Does anyone have the correct options for PHP?
Fixed, there was a post on a similar topic, in which the MIME type was added to the file. It works with /message/video /message/image /message/doc
PHP Code for image <?php $url = 'http://localhost:3333/message/image?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'imagen1.jpg'; $id = '1122334455'; $caption = ''; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'image/jpeg'), 'id' => $id, 'caption' => $caption ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
PHP For PDF/Etc <?php $url = 'http://localhost:3333/message/doc?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'pdf1.pdf'; $filename = 'pdf1.pdf'; $id = '1122334455'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'application/pdf'), 'id' => $id, 'filename' => $filename ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
For Video <?php $url = 'http://localhost:3333/message/video?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'video1.mp4'; $id = '11223344455'; $caption = ''; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'video/mp4'), 'id' => $id, 'caption' => $caption ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
Fully working and tested 2023/07/15
Fixed, there was a post on a similar topic, in which the MIME type was added to the file. It works with /message/video /message/image /message/doc
PHP Code for image
<?php $url = 'http://localhost:3333/message/image?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'imagen1.jpg'; $id = '1122334455'; $caption = ''; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'image/jpeg'), 'id' => $id, 'caption' => $caption ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
PHP For PDF/Etc
<?php $url = 'http://localhost:3333/message/doc?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'pdf1.pdf'; $filename = 'pdf1.pdf'; $id = '1122334455'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'application/pdf'), 'id' => $id, 'filename' => $filename ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
For Video
<?php $url = 'http://localhost:3333/message/video?key=e4cda99a-66eb-40b3-adf3-7d7c943f55a0'; $file = 'video1.mp4'; $id = '11223344455'; $caption = ''; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'file' => new CURLFile($file,'video/mp4'), 'id' => $id, 'caption' => $caption ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
Fully working and tested 2023/07/15
I have not experience on posting code, even on posting single comment.
From an old post:
I noticed a somewhat strange behavior, when I send images via api, I receive confirmation of error=false and the sending happens normally, but not to the cell phone, only to the destination's whastapp web. Has anyone had a similar situation?
This is exactly what happened today, with Node, Yarn, Etc up to date
The PHP code used to send, similar code work fine with Text messages
$url = 'http://localhost:3333/message/image?key=f4df5725-5a1c-409e-9c0f-6ca90b4d77ec'; $file = 'imagen1.jpg'; $id = '66566598888123'; $caption = ''; $postFields = array( 'file' => curl_file_create($file), 'id' => $id, 'caption' => $caption ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $response = curl_exec($ch); curl_close($ch); // Manejar la respuesta echo $response;