Use this for more debugging details: ```php $pho...
# general-english
o
Use this for more debugging details:
Copy code
php
$phoneNumberId = "123456";  // Replace with the actual phone number ID if known
$authToken = getenv('VAPI_API_KEY');  // Ensure this is the correct environment variable

$phoneData = [
    "twilioPhoneNumber" => $request->phone_number,
    "twilioAccountSid" => $request->AccountSid,
    "twilioAuthToken" => $request->AuthToken,
    "name" => $bot['bot_name'],
    "serverUrl" => $request->server_url
];

// Print the phone data to verify its contents
echo "<pre>";
print_r($phoneData);
echo "</pre>";

$response = Http::withHeaders([
    'Authorization' => 'Bearer ' . $authToken,
])->post(env('VAPI_BASE_URL') . "/phone-number/import/twilio/", $phoneData)->json();

// Print the response from the import API call
echo "<pre>";
print_r($response);
echo "</pre>";

// Check for errors in the response
if (isset($response['error'])) {
    return response()->json(['Error' => $response['message']], 400);
} else {
    $phoneNumberId = $response['id'];  // Assuming the response contains the phone number ID

    // Retrieve the phone number details to check for serverUrl
    $detailsResponse = Http::withHeaders([
        'Authorization' => 'Bearer ' . $authToken,
    ])->get(env('VAPI_BASE_URL') . "/phone-number/{$phoneNumberId}")->json();

    // Print the details response for debugging
    echo "<pre>";
    print_r($detailsResponse);
    echo "</pre>";

    // Check if 'serverUrl' is present in the response
    if (isset($detailsResponse['serverUrl'])) {
        echo "Server URL: " . $detailsResponse['serverUrl'];
    } else {
        echo "Server URL is not present in the response.";
    }
}
2 Views