First thing I see is that youāre trying to send a POST request to the colour API, which it doesnāt accept and thatās why itās returning that error. If you change that to a GET it should be fine.
I would go a more reduced code route but it all get you to the same place in the end.
let hex = pm.variables.replaceIn('{{$randomHexColor}}');
pm.sendRequest(`https://www.thecolorapi.com/id?hex=${hex.replace('#', '')}`, function (err, response) {
pm.variables.set("payload", JSON.stringify({
hex: `${hex}`,
rgb: `${response.json().rgb.value}`,
name: `${response.json().name.value}`
}))
});
After you have this working, ensure that youāre creating tests to check for a successful response and that it includes the properties.
Danny, you are my hero!! Thanks - I would have never figured this out!
I LOVE your code - concise! I esp appreciate the '${response.jason()ā¦ - this is one of those things I couldnāt figure out.
I think one of the things that is really confusing is using variables:
{{variable}} - used in headers, query params
{{$variable}} - this is the built-in pseudo vars
{$variable} - I guess a template for receiving variable?
āvariableā - console.log(āvariableā)
variable - guess just a JAVA variable
ā¦Iāll figure this out in time.