cURL PHP Example

     12059923);
    echo "Request Payload: " . json_encode($array_filter) . "\n";
    $data_json = json_encode($array_filter);

    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Ensure the response is returned as a string
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Authorization: Bearer $token",
        "Cache-Control: no-cache",
        "Content-Type: application/json"
    ]);
    curl_setopt($ch, CURLOPT_VERBOSE, true); // Enable verbose mode
    curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); // Output verbose information to STDERR
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

    // Execute cURL request
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        echo 'Error: ' . curl_error($ch);
    } else {
        // Print raw response for debugging
        echo "Raw Response:\n$response\n";

        // Decode JSON response
        $data = json_decode($response, true);
        var_dump($data);

        echo "Is array: " . (is_array($data) ? 'true' : 'false') . "\n";

        // Check for JSON decoding errors
        if (json_last_error() !== JSON_ERROR_NONE) {
            echo "JSON Decode Error: " . json_last_error_msg() . "\n";
            // Handle non-JSON response
            echo "Response is not valid JSON. Raw response below:\n$response";
        } else {
            // Print entire array structure for debugging
            echo "
";
            print_r($data);
            echo "
"; } } // Close cURL session curl_close($ch); ?>