From 13d6b766d0ea6f039c186d4990d52f9d7097fedd Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Fri, 13 Oct 2023 13:59:16 +0530 Subject: [PATCH] fix: added support for application/json body --- src/base/RequestClient.ts | 9 +++++++-- src/rest/PreviewMessaging.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/rest/PreviewMessaging.ts diff --git a/src/base/RequestClient.ts b/src/base/RequestClient.ts index 002f2866e4..f48b00b13f 100644 --- a/src/base/RequestClient.ts +++ b/src/base/RequestClient.ts @@ -190,8 +190,13 @@ class RequestClient { validateStatus: (status) => status >= 100 && status < 600, }; - if (opts.data) { - options.data = qs.stringify(opts.data, { arrayFormat: "repeat" }); + if (opts.data && options.headers) { + if(options.headers["Content-Type"] === "application/x-www-form-urlencoded") { + options.data = qs.stringify(opts.data, { arrayFormat: "repeat" }); + } + else if(options.headers["Content-Type"] === "application/json") { + options.data = opts.data; + } } if (opts.params) { diff --git a/src/rest/PreviewMessaging.ts b/src/rest/PreviewMessaging.ts new file mode 100644 index 0000000000..3569a2ae8d --- /dev/null +++ b/src/rest/PreviewMessaging.ts @@ -0,0 +1,15 @@ +import PreviewMessagingBase from "./PreviewMessagingBase"; +import {MessageListInstance} from "./previewMessaging/v1/message"; + +class PreviewMessaging extends PreviewMessagingBase { + /** + * @deprecated - Use v1.messages; instead + */ + get messages(): MessageListInstance { + console.warn( + "messages is deprecated. Use v1.messages; instead." + ); + return this.v1.messages; + } +} +export = PreviewMessaging