From 1e43d36032e2d1e2c9c82833513a9ef4456cadeb Mon Sep 17 00:00:00 2001 From: Rui Barbosa Date: Mon, 17 Jun 2024 18:12:59 -0400 Subject: [PATCH] fix form-data and binary body params missing --- src/PostmanConversions.js | 24 +++++++++++++++++++++++- src/postmanAPI.js | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/PostmanConversions.js b/src/PostmanConversions.js index 545ea51..f075648 100644 --- a/src/PostmanConversions.js +++ b/src/PostmanConversions.js @@ -17,8 +17,15 @@ const requestFromLocal = (localRequest) => { let dataMode = null let rawModeData = null if (localRequest.request.body && localRequest.request.body.urlencoded) { - data = dataFromLocalURLEncode(localRequest.request.body.urlencoded) dataMode = localRequest.request.body.mode + if (dataMode === 'formdata') { + dataMode = 'params' + data = dataFromFormData(localRequest.request.body.formdata) + } else if (dataMode === 'file') { + dataMode = 'binary' + } else { + data = dataFromLocalURLEncode(localRequest.request.body.urlencoded) + } rawModeData = localRequest.request.body.raw } @@ -137,6 +144,21 @@ const dataFromLocalURLEncode = (localFormData) => { return data } +const dataFromFormData = (localFormData) => { + const data = [] + for (const param of localFormData) { + const item = { + key: param.key, + description: param.description, + value: param.value, + enabled: !param.disabled, + type: param.type + } + data.push(item) + } + return data +} + module.exports = { requestFromLocal, responseFromLocal diff --git a/src/postmanAPI.js b/src/postmanAPI.js index 7924dd2..b4f5b66 100644 --- a/src/postmanAPI.js +++ b/src/postmanAPI.js @@ -28,7 +28,7 @@ class Collection { async merge (destinationCollectionId, strategy = 'updateSourceWithDestination') { return await this.axios.post( 'https://api.getpostman.com/collections/merge', - { source: this.collectionId, destination: destinationCollectionId, strategy }, + { source: this.collectionId, destination: destinationCollectionId }, //, strategy }, { timeout: 1000 * 60 * 5 } // 5 minutes ).then(function (response) { if (response.status !== 200) { @@ -144,6 +144,7 @@ class Request { request, { params: { folder: folderId } } ).then(function (response) { + // console.log('response', response) if (response.status !== 200) { throw new Error(`Error creating request ${request.id}: ${response.status} ${response.statusText}`) } else {