The code is given as: let incomingPayload = JSON.parse(globals.previousRequest).data; pm.collectionVariables.set("newPayload", incomingPayload.message)
Body:
{{newPayload}}
Error:
“There was an error in evaluating the Pre-request Script:JSONError: Unexpected token u in JSON at position 0”
I can’t for the life of me understand this error or spot how I misunderstood the instructions.
I tested further by trying console.log(pm.globals.get(‘previousRequest’)); at the beginning of the Pre Script and it is undefined. I don’t seem to understand what is expected from this step at all.
That script in the echo request relates to the functionality of the Webhook you created when it’s Triggered. It wouldn’t work in isolation or as a single request.
When you trigger the Webhook, you should see the output of this in the monitor that what created for it.
I’m not really sure what the problem is here, the echo request is not intended to be run as a single request.
With the pre-request code, that’s very specific to the webhook functionality, it’s going to error.
Triggering the webhook, if that’s been created correctly, will run the Collection in the Monitor and the results of that can be seen on the monitors console.
I’m not sure I’ve ever found the expected console logs - 'Echoing my payload: ', pm.response.json().data
Going back over this again, it appears somehow I was running the previous day’s (28 UI testing) collection in my monitor. I deleted the monitor, verified I had Day 29’s Collection Id as my variable and triggered a new webhook.
It is running properly now. I get that the first echo call wasn’t supposed to run on its own, I guess it was just where I started looking when my monitor wasn’t running properly.