Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-php): send an empty session config as a JSON object
Yudhi Armyndharis96ce3f870392
diff --git a/sdk/php/src/Resources/SessionsResource.php b/sdk/php/src/Resources/SessionsResource.phpindex 41ef26c9d..e8fcd124f 100644--- a/sdk/php/src/Resources/SessionsResource.php+++ b/sdk/php/src/Resources/SessionsResource.php@@ -87,6 +87,11 @@ class SessionsResource*/public function create(array $body): array{+ // config is a map: an empty PHP array would serialize as a JSON list [] and be rejected by the+ // gateway's object validation. Cast the empty map to stdClass so it encodes as {}.+ if (isset($body['config']) && $body['config'] === []) {+ $body['config'] = new \stdClass();+ }return $this->http->request('POST', '/api/sessions', [], $body);}diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.phpindex 761d5306e..92259fe4e 100644--- a/sdk/php/tests/ResourcesTest.php+++ b/sdk/php/tests/ResourcesTest.php@@ -250,6 +250,10 @@ class ResourcesTest extends TestCase$backend->on(200, ['id' => 'm1']);$client->messages->sendTemplate('s', ['chatId' => 'c', 'templateName' => 't', 'vars' => []]);$this->assertSame('{"chatId":"c","templateName":"t","vars":{}}', $backend->rawBody(2));++ $backend->on(201, ['id' => 's1']);+ $client->sessions->create(['name' => 'n', 'config' => []]);+ $this->assertSame('{"name":"n","config":{}}', $backend->rawBody(3));}public function testBulkItemsEncodeEmptyVariablesAsJsonObject(): void