true, CURLOPT_HTTPHEADER => [ 'Accept: application/json', ], CURLOPT_TIMEOUT => 10, ]); $body = curl_exec($ch); if ($body === false) { fwrite(STDERR, 'cURL error: ' . curl_error($ch) . PHP_EOL); curl_close($ch); exit(1); } $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE) ?: ''; curl_close($ch); if ($status < 200 || $status >= 300) { fwrite(STDERR, "HTTP {$status}" . PHP_EOL); fwrite(STDERR, $body . PHP_EOL); exit(1); } if (!preg_match('/^application\/json\b/i', $contentType)) { fwrite(STDERR, "Unexpected Content-Type: {$contentType}" . PHP_EOL); exit(1); } try { $payload = json_decode($body, true, 512, JSON_THROW_ON_ERROR | JSON_BIGINT_AS_STRING); } catch (JsonException $e) { fwrite(STDERR, 'JSON error: ' . $e->getMessage() . PHP_EOL); exit(1); } $profile = $payload['profile'] ?? null; $features = $payload['features'] ?? null; if (!is_array($profile) || !isset($profile['name'], $profile['plan'], $profile['account_id']) || !is_array($features)) { fwrite(STDERR, "JSON response did not include the expected profile and features fields" . PHP_EOL); exit(1); } echo "HTTP {$status}" . PHP_EOL; echo "Content-Type: {$contentType}" . PHP_EOL; echo "Name: " . $profile['name'] . PHP_EOL; echo "Plan: " . $profile['plan'] . PHP_EOL; echo "Account ID type: " . gettype($profile['account_id']) . PHP_EOL; echo "Feature count: " . count($features) . PHP_EOL;