Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk-js): keep a path query string when request adds params

Yudhi Armyndharisf9449ead3d60
diff --git a/sdk/javascript/src/http.ts b/sdk/javascript/src/http.ts
index 0fcd4dfba..20edaeaaa 100644
--- a/sdk/javascript/src/http.ts
+++ b/sdk/javascript/src/http.ts
@@ -75,7 +75,8 @@ export function buildUrl(baseUrl: string, path: string, query?: object): string
params.append(key, String(value));
}
const qs = params.toString();
- return qs ? `${url}?${qs}` : url;
+ // A raw path may already carry a query string; extend it rather than start a second one.
+ return qs ? `${url}${path.includes('?') ? '&' : '?'}${qs}` : url;
}
/**
diff --git a/sdk/javascript/test/client.test.ts b/sdk/javascript/test/client.test.ts
index 0c15784d1..3edaaf587 100644
--- a/sdk/javascript/test/client.test.ts
+++ b/sdk/javascript/test/client.test.ts
@@ -137,6 +137,12 @@ describe('OpenWAClient', () => {
expect(t.lastCall!.url).not.toContain('from=');
});
+ it('appends query params to a query string already in the path', async () => {
+ const t = new MockTransport().passthrough({ status: 200, body: [] });
+ await client(t).request({ method: 'GET', path: '/api/sessions?limit=5', query: { name: 'x' } });
+ expect(t.lastCall!.url).toBe('http://localhost:2785/api/sessions?limit=5&name=x');
+ });
+
it('maps a 404 to OpenWANotFoundError with parsed body', async () => {
const t = new MockTransport().on('GET', '/api/sessions/missing', {
status: 404,