Day 25: Getting [object Object] for payload

My Fellow Postmanauts,

I must be fried. I only have 3 days left to complete the last 5 challenges so this one is slipping away from me.

I cannot for the life of me get the {{payload}] env variable to update to match the hexPayload set in the pre-script. Here is my pre-script code.

let color_var = pm.variables.replaceIn('{{$randomHexColor}}');
  let hex_var = color_var.slice(1);

let hexPayload = pm.sendRequest("" + hex_var, function (err, response) {
    let JSONResponse = response.json();
    let bodyBuild = {
        hex: JSONResponse.hex.value,
    return JSON.stringify(bodyBuild);});


Hi @terry-brooks

Try this;

const color_var = pm.variables.replaceIn('{{$randomHexColor}}');

pm.sendRequest(`${color_var.slice(1)}`, (err, response) => {
    if (err) 
        throw err; 
        let data = response.json();
        const bodyBuild = {
            hex: color_var,
            rgb: data.rgb.value,
        pm.collectionVariables.set("payload", JSON.stringify(bodyBuild));

The [object Object] for payload I believe is how/where you were using stringify.

There is some useful info on this here;