ArrchanaMohan
ArrchanaMohan

Reputation: 2566

How to use dynamic request body for HTTP Request plugin

I can able to hit the end point URL along with request body for POST method. But I just want to know how can I use different data in JSON request body to hit the same end point URL that mentioned in the HTTP Request Jenkins plugin.

Sample JSON request body:

{
  "duration": "2019-02-10T08:08:12.300Z",
  "domain": "Google Pay",
  "priority": "1",
  "flowId": 022,
  "subFlowId": 110,
  "productId": 180
}

For that above request body I just want to change the "subFlowId" value for single build. Like The above request JSON file need to hit the end point with different values.

I have a list of payloads which is available in workspace, and just want to pass those JSON (above is reference) content as request body in HTTP Request plugin.

How can I achieve this?

Upvotes: 0

Views: 1386

Answers (1)

hakamairi
hakamairi

Reputation: 4678

One way to do that

import groovy.json.JsonOutput

def myJson = '{"subFlowId":"1.0.0"}'
def myObject = JsonOutput.toJson(myJson)
myObject.subFlowId = 'something cool'
//back to string
myJson = JsonOutput.prettyPrint(myObject)

Upvotes: 0

Related Questions