I am posting json and audio file to my api built on laravel with the code below
$endPoint = 'http://localhost:9000/api/audio/send';
$apiKey = 'anvx7P7ackndaD8MvXlufSaG4uJ901raoWIwMPGZ93dkH';
$url = $endPoint . '?key=' . $apiKey;
$curlFile = new \CURLFile('/Users/desktop/myapp/public/Voice/aaaah.wav');
$data = array("request" =>
json_encode(array("test" => "First audio ",'recipient' =>['442342342', '35345242'])) . ";
type=application/json","file" => "@d8696c304d09eb1.wav;type=audio/wav");
$ch = curl_init();
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$result = json_decode($result, TRUE);
curl_close($ch);
return $result;
When i submit my json to the api, it returns null from the api. Meaning no data is being posted to my api. Is there any error with how i am posting my json and audio file to the laravel api please?
PS: Beginner in PHP