Encoding query parameter excluding variables in postman\newman

Hi Experts,

I did search for any help already existing, couldn’t find though.

Appreciate your help with this:
a. The API that I am testing accepts json payload as query param and expects the entire payload to be base64 encoded.

POST {{URI}}/Directory?user={{UserName}}&password={{Password}}=&json= (ENCODED JSON Payload)

b. These APIs are tested using Postman chaining that requires GETting & SETting global & local variables and chaining them in a POSTMAN collection & run using newman in CI. The Payload in queryparam has variables Set

c. Postman does provide a way to encode & decode, but entire payload will be encoded\decoded. There is no way to skip encoding\decoding the variables.

d. Hence the ‘Variable’ itself gets encoded and the ‘resource’ created will be of the ‘variable name’ rather than the name passed\set in that variable.

Question is: How to ‘EXCLUDE’ variables in the queryparam while encoding rest of the param\payload?

Thanks so much in advance for the help!

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

How are you doing the base64 encoding of the entire payload?

Something you could to is explicitly encode the variable you want in a prerequest script and use that as your query param.

const queryParam = pm.variables.get('queryParam');
const encodedQueryParam = btoa(queryParam);
pm.variables.set('encodedQueryParam', encodedQueryParam);

Then use that variable in your request

Hi Allen,
I am encoding the payload statically/manually before making it part of the collection.

The question is about encoding the entire query parameter (json payload) and not only the variable.I can encode the variable in prerequest script and pass in payload, is there a way to encode the payload itself ?
While doing do it should nt again encode the variable.