最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - How to send a Bruno request with a dynamic object in the body? - Stack Overflow

programmeradmin0浏览0评论

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 0
Add a comment  | 

1 Answer 1

Reset to default 0

It 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);
发布评论

评论列表(0)

  1. 暂无评论