Need to have dynamic dates in JSON Post request

I don’t know how to do that, Master Jedi… :stuck_out_tongue:

Hi Amanda,

I think you can handle this like so:

1.) You should be able to add parameter handles to your request body. Using your JSON snippet as an example:

    "occursOn" : "2019-12-25"

You should be able to parameterize the object value just like you would for a normal Test Object:

    "occursOn" : "${occursOn}"

2.) Now we need to generate a date of “today’s date + 1 month” and pass it to the request body. You can accomplish this using Java’s LocalDate class, and pass the value to the WS object from your script like so:

import java.time.LocalDate

String todaysDatePlusOne = LocalDate.now().plusMonths(1).toString()
WS.sendRequest(findTestObject('path/to/ws/object', ['occursOn' : todaysDatePlusOne]))

Give this a try and let me know :slight_smile:

2 Likes

Does this need to be in say a test case or can I somehow put it into the Query Parameters of the Request?

I’m assuming by this, you mean the code in 2.) from above. Yes, it would either need to be in the test case, or, even better, if this is something you can see yourself using across multiple scripts, you could create a custom keyword to do it. I can elaborate on this if you’d like.

Query parameters are a separate topic altogether.

Ok, custom keyword - I’ll go down that path.

and I think I get it by what you posted now…I think I understand…let’s see if the padawan has finally cleared the fog from the force…

:slight_smile:

1 Like

It’s all a process, just like every other skill :slight_smile: Let me know if you need any clarifications.

1 Like

The lowly lazy padawan finally cleared the fog. Got it set up as a CustomKeyword, got it tagged in the test case (which is what I think @kazurayam was trying to get me to do in the first place, my apologies for being slow on this one).

AND IT WORKED.

Holy smokes guys. Thanks for hanging in there and basically dragging me along by the nose. I am so very grateful for the help, Jedi Masters

4 Likes

Glad to help :ok_hand:

I remember grappling with stuff like this. Sometimes you just have to bang your head into the wall until it clicks, just how it is. But I guarantee you, now you know this approach to that particular problem, you will find other places where the same idea can be applied, which leads to cleaner code, which in turn leads to more opportunities for learning and ways of doing things better/simpler.

(Also, sometimes when we try and help each other, the biggest challenge is getting our point across in a clear way so that others can interpret what is happening in our brains, which isn’t always easy.)

We all stand on the shoulders of giants, as they say!

1 Like

(Humbly marking my answer as the solution…)

1 Like

Absolutely! Thought I had but I must have missed it!! Again, thanks so much!

Glad to hear that.

@Amanda_Perkins1 nicely done, young padawan.
stronger than you think the code may be inside you

1 Like

Amanda can you help me with the code that you used in your custom keyword and that was used in json body ?