I am trying to send a request with a dynamic object in the json-body.
The idea is: The previous request saves an object as an environment variable. The current request sends the object in the body.
body:json {
"id": "id123",
"input": "{{objectToSend}}"
}
The issue is, Bruno does not use the variables object value. Instead the value is the string "{{objectToSend}}"
Here the timeline:
> POST <myURL>
> content-type: application/json
> data
{
"id": "id123",
"input": "{{objectToSend}}"
}
Example object to be used:
{
"augend":2,
"addend":3
}
or
{
"multiplicand": 2,
"multiplier": 3
}
Is there a way that Bruno uses a variables object as a value in the body?
I tried to stringify the variable but this creates an invalid json.
I am trying to send a request with a dynamic object in the json-body.
The idea is: The previous request saves an object as an environment variable. The current request sends the object in the body.
body:json {
"id": "id123",
"input": "{{objectToSend}}"
}
The issue is, Bruno does not use the variables object value. Instead the value is the string "{{objectToSend}}"
Here the timeline:
> POST <myURL>
> content-type: application/json
> data
{
"id": "id123",
"input": "{{objectToSend}}"
}
Example object to be used:
{
"augend":2,
"addend":3
}
or
{
"multiplicand": 2,
"multiplier": 3
}
Is there a way that Bruno uses a variables object as a value in the body?
I tried to stringify the variable but this creates an invalid json.
Share Improve this question asked Feb 5 at 16:16 user29513262user29513262 111 bronze badge 01 Answer
Reset to default 0It does not seem possible to use objects stored in a variable in the Body section. Did several attempts, but one way or the other the variable will unfortunately always be interpreted as a string.
It is possible however to achieve this using the Pre Request script, as displayed below.
// Simulate setting environmental variable in previous request
objectFromPreviousRequest = {"multiplicand": 2, "multiplier": 3};
bru.setEnvVar("objectToSend", objectFromPreviousRequest);
const bodyToSend = {"id": "id123", "input": bru.getEnvVar("objectToSend")}
req.setBody(bodyToSend);