I thought the problem was with the email address in the body, not the OAuth setup!
You are getting 400 bad requests, which would seem to indicate an issue with the request, rather than the authentication. (Which would usually be a 401).
Your environment variable appears to be called “user_email_id” (or potentially randomEmail) but your body (and pre-request script) is showing {{email}}.
As mentioned, current values are not exported, so in your screenshot, randomEmail would be undefined as it does not have an initial value.
Not sure if the screenshot is showing all of the environment variables though.
I’m assuming that you do have an email variable somewhere, as it would seem the code in the IF block is being triggered.
Where is the “value of yourEnvironmentVariable” coming from? As I can’t see that in your IF block?
If you have a bunch of required variables, you could add a test for this in your pre-request script.
For example…
pm.test("Pre-request check for Environment Variables", function () {
let vars = ['clientId', 'clientSecret', 'tenantId', 'username', 'password', 'scope'];
vars.forEach(function (item) {
// console.log(item);
pm.expect(pm.environment.get(item), item + " variable not set").to.not.be.undefined;
pm.expect(pm.environment.get(item), item + " variable not set").to.not.be.empty;
});
})
You would add the code to increment the email address within that test block after the assertions.
Or you could just console log all environment variables. (Are any being returned, or is it just the email variable that is missing?)
pm.environment.toJSON().values.forEach((object) => {
console.log(`${object.key} : ${object.value}`);
});