Manipulating strings before posting

Hi all,
I have a question surround session and creating data to send to a url. I will describe the scenario and then show up some code.

I want to test what offer I want to get to sell things based on a sku/id and the type of account a person has.
I have to do some post processing on the entire inventory to generate a payload that will work with the WS I want to use for the accounts I am expecting and there are about 20 fields but the one I can about is account:<account_number>. So it will basically look something like [{“payload”: “{'schema”: “5.0”, “account”: <account_number>, “id_1”: 1, “id_2”, “2”…}"}, {“payload”: “{'schema”: “5.0”, “account”: <account_number>, “id_1”: 3, “id_2”, “4”…}"}…]
I have an endpoint that will give me all the accounts I need.
I need to merge these to to replace a field in the payload that it goes form {'schema": “5.0”, “account”: <account_number>, “id_1”: 1, “id_2”, “2”…} to 'schema": “5.0”, “account”: "1234", “id_1”: 1, “id_2”, “2”…} based ont he previous web service call.
So I have a feeder feeding the file of payloads and called the url so that there is just a shared list that will be used in all scenarios.
Now I need to figure out how to replace that <account_number> that will be in the feeder session var payload with the number. I have all the data but I can’t seem to manipulate the payload string to inject the account numbers.

If I modify the payload in like an exec({session => }) block then the changes are not reflected in the exec(http()) block. If I try to do it inline, the el expression isn’t referenced until a point where I can’t call the scala replace function.

Is there a way to modify that payload so that in some way shape or form (declaring a local variable, new session attribute, anything I don’t care how ugly it is) to get this to work. I have tried to set a new session attribute but just get errors saying attribute not found in the http block even the exec({session=> }) block is before it. Here is the code, let me know if you have any ideas.

Thanks for all the help as we are trying to introduce this to the company and they are responding very well. We just need to figure out how to do all this dynamic content better.


object postNgpOffers {

val search = foreach(accountNumbers, “account”) {

var temp =""

// exec {

// session =>

// session.set(“stringPayload”, session(“payload”).as[String].replace(“acct_id_replace_me”, session(“accountNumber”).as[String]))

// session

// }"This is the log to see where the message is being logged. ")"Account Number " + “accountNumber”)

//“Message : " + StringBody(”${payload}".replace(“acct_id_replace_me”, “{$accountNumber}”)))



session =>

temp = session(“payload”).as[String].replace(“acct_id_replace_me”, session(“account”).as[String])


.pause(100 millisecond)



http(“NGP get Offers For Account”)






.exec({session=>"URL " + ngpOffersUrl + " : Payload : " + temp)






And once again I’m an idiot, all you need to do is ensure the session.set() is the last line of the block and remove the session at the end of the block and it works fine.

So more like this is all you need and you can string as many as you need with just .exec({}).exec({}):

exec({ session => session.set(“key”,"value)}


Really need to start reading the documentation more carefully!