I have tried 2 ways to do this both resulted in same
Directly manipulating url
const request = new Request({
header: requestHeader,
url: `${apiEndpoint}?${new URLSearchParams(params).toString()}}`,
method: 'GET',
auth: null,
});
using QueryParam
Object.keys(params).forEach((key) => {
const queryParams = new QueryParam({
key,
value: params[key],
});
request.addQueryParams(queryParams);
});
both result into query property like this
"query": [
{
"key": "members",
"value": {
"prop1": {
"key": "keyName",
"value": "VALUE"
},
"prop2": {
"key": "keyName2",
"value": "VALUE2"
},
]
},
{
"key": "reference",
"value": {
"prop1": {
"key": "keyName",
"value": "VALUE"
},
"prop2": {
"key": "keyName2",
"value": "VALUE2"
},
}
},
{
"key": "Type",
"value": {
"_postman_propertyName": "QueryParam",
"_postman_propertyIndexKey": "key",
"_postman_propertyAllowsMultipleValues": true
}
},
{
"key": "_postman_listIndexKey",
"value": "key"
},
{
"key": "_postman_listAllowsMultipleValues",
"value": true
}
],
when this data is imported into postman it results in this url
{{url}}?members&reference&Type&_postman_listIndexKey=key&_postman_listAllowsMultipleValues
I cross checked by exporting postman collection and there query is array of objects
{
"key": "KEY1",
"value": "VALUE1"
},
{
"key": "KEY2",
"value": "VALUE2"
},
This happens when using collection.toJSON()
, when request.toJSON()
is used it in expected format.