Commit 4f5902d2 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: Swiss API needs Content-Type + empty body {} for bodiless POSTs

The API rejects bodiless POSTs without Content-Type (415 Unsupported Media
Type) AND rejects Content-Type with literally no body (Body cannot be empty).
Solution: always send Content-Type, and for POST/PATCH/PUT with null body,
send empty object {} as body.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 102e8b47
...@@ -15,14 +15,15 @@ class ApiProxy ...@@ -15,14 +15,15 @@ class ApiProxy
public static function swiss(string $method, string $path, ?array $body = null, ?string $token = null): array public static function swiss(string $method, string $path, ?array $body = null, ?string $token = null): array
{ {
$headers = []; $headers = ['Content-Type: application/json'];
if ($body !== null) {
$headers[] = 'Content-Type: application/json';
}
$authToken = $token ?? self::getSwissToken(); $authToken = $token ?? self::getSwissToken();
if ($authToken) { if ($authToken) {
$headers[] = 'Authorization: Bearer ' . $authToken; $headers[] = 'Authorization: Bearer ' . $authToken;
} }
$upperMethod = strtoupper($method);
if ($body === null && in_array($upperMethod, ['POST', 'PATCH', 'PUT'])) {
$body = [];
}
return self::request($method, SWISS_API_URL . $path, $body, $headers); return self::request($method, SWISS_API_URL . $path, $body, $headers);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment